我希望得到git show -s --format=%H在Dulwich中的行为,即获得由HEAD指向的完整提交哈希。然而,事实证明,porcelain.show() function的行为与git show非常相似,但似乎不知道任何其他选项,比如Git。
考虑到porcelain.describe()的行为类似,我并不感到惊讶。但是,对于HEAD的完整提交哈希,我在Dulwich有什么替代方法呢?
对于缩略语--尽管硬编码为7个字符(!) --我可以使用前面提到的porcelain.describe()。
发布于 2022-10-25 13:28:05
通过咨询the code for porcelain.describe(),我们可以把这些东西拼凑在一起。
open_repo_closing为dulwich.repo.BaseRepo class提供了一个很好的上下文管理器,contextlib.closing behaviorBaseRepo.head()将信息包含为bytes最小的实现可能如下所示:
def get_latest_hash(repo):
from dulwich.porcelain import open_repo_closing
with open_repo_closing(repo) as r:
return r.head().decode("ascii")比我最初预计的要简单。
https://stackoverflow.com/questions/74194840
复制相似问题