def get_git_commit(repo): try: # SHA should always be valid utf-8 return to_utf8(repo.head()) except KeyError: return None
def commit(repo, commit_msg): if not commit_msg: commit_msg = 'dulwich_' + U.stime() if not py.isbytes(commit_msg): commit_msg = commit_msg.encode('utf-8') index = repo.open_index() new_tree = index.commit(repo.object_store) if new_tree != repo[repo.head()].tree: bhash = repo.do_commit(commit_msg, tree=new_tree) return bhash, commit_msg else: return b'', py.No("Empty commit!")
def __init__(self, 窗口): super().__init__() self.窗口 = 窗口 self.vue.存檔資料 = [] self.當前工程配置 = None if (此處 / '存檔資料/存檔資料.yaml').is_file(): with open(此處 / '存檔資料/存檔資料.yaml') as f: self.vue.存檔資料 = yaml.safe_load(f) repo = dulwich.repo.Repo('.') 最後提交unix時間 = repo[repo.head()].author_time self.vue.最後提交時間 = datetime.datetime.fromtimestamp(最後提交unix時間).strftime( '%y-%m-%d') self.vue.librian版本 = librian.__version__
def functionWorker(tname, allocate_pkey): if allocate_pkey: pkey_thread_mapper(tname) runner = pyperf.Runner(loops=1) runner.metadata['description'] = ("Dulwich benchmark: " "iterate on all Git commits") repo_path = os.path.join(os.path.dirname(__file__), 'data', 'asyncio.git') repo = dulwich.repo.Repo(repo_path) head = repo.head() runner.bench_func('dulwich_log', iter_all_commits, repo) repo.close() del runner pymem_reset()
def faasm_main(): if os.environ.get("PYTHONWASM") == "1": repo_path = "/lib/python3.7/site-packages/pyperformance/benchmarks/data/asyncio.git" else: repo_path = "/usr/local/code/faasm/venv/lib/python3.6/site-packages/pyperformance/benchmarks/data/asyncio.git" if not exists(repo_path): repo_path = "/usr/local/lib/python3.6/dist-packages/pyperformance/benchmarks/data/asyncio.git" repo = dulwich.repo.Repo(repo_path) head = repo.head() # Iterate on all changes on the Git repository for _ in repo.get_walker(head): pass repo.close()
""" Iterate on commits of the asyncio Git repository using the Dulwich module. """ import os import perf import dulwich.repo def iter_all_commits(repo): # iterate on all changes on the Git repository for entry in repo.get_walker(head): pass if __name__ == "__main__": runner = perf.Runner() runner.metadata['description'] = ("Dulwich benchmark: " "iterate on all Git commits") repo_path = os.path.join(os.path.dirname(__file__), 'data', 'asyncio.git') repo = dulwich.repo.Repo(repo_path) head = repo.head() runner.bench_func('dulwich_log', iter_all_commits, repo) repo.close()
def get_git_patch(repo, unstaged=True): final_changes = {} store = OverrideObjectStore(repo.object_store) try: head = repo.head() except KeyError: return None tree_id = repo[head].tree tree = repo[tree_id] index = repo.open_index() normalizer = repo.get_blob_normalizer() filter_callback = normalizer.checkin_normalize object_store = repo.object_store blob_from_path_and_stat = dulwich.index.blob_from_path_and_stat cleanup_mode = dulwich.index.cleanup_mode lookup_path = tree.lookup_path repo_path = repo.path.encode(sys.getfilesystemencoding()) def lookup_entry(path): absolute_path = os.path.join(repo_path, path) if os.path.isfile(absolute_path): st = os.lstat(absolute_path) # TODO: Building the blob means that we need to load the whole # file content in memory. We should be able to compute the sha # without needed to load the whole blob in memory. blob = blob_from_path_and_stat(absolute_path, st) blob = filter_callback(blob, path) blob_id = blob.id mode = cleanup_mode(st.st_mode) # Check if on-disk blob differs from the one in tree try: tree_blob = lookup_path(object_store.__getitem__, path) except KeyError: # Lookup path will fails for added files store[blob_id] = blob else: # If the blob for path in index differs from the one on disk, # store the on-disk one if tree_blob[1] != blob_id: store[blob_id] = blob return blob_id, mode elif os.path.isdir(absolute_path): try: tree_blob = lookup_path(object_store.__getitem__, path) except KeyError: # If the submodule is not in the store, it must be in index # and should be added index_entry = index[path] return index_entry.sha, index_entry.mode tree_mode = tree_blob[0] if dulwich.objects.S_ISGITLINK(tree_mode): return tree_blob[1], tree_mode else: # We shouldn't be here? raise KeyError(path) else: # Indicate that the files has been removed raise KeyError(path) # Merges names from the index and from the store as some files can be only # on index or only on the store names = set() for (name, _, _) in object_store.iter_tree_contents(tree_id): names.add(name) names.update(index._byname.keys()) final_changes = dulwich.index.changes_from_tree(names, lookup_entry, repo.object_store, tree_id, want_unchanged=False) # Generate the diff diff = BytesIO() def key(x): # Generate a comparable sorting key paths = tuple(p for p in x[0] if p) return paths for (oldpath, newpath), (oldmode, newmode), (oldsha, newsha) in sorted(final_changes, key=key): dulwich.patch.write_object_diff(diff, store, (oldpath, oldmode, oldsha), (newpath, newmode, newsha)) diff.seek(0) diff_result = diff.getvalue() # Detect empty diff if not diff_result: return None return diff_result