【问题标题】:How would I go about getting the full commit hash in Dulwich?我将如何在 Dulwich 中获取完整的提交哈希?
【发布时间】:2022-10-25 21:28:05
【问题描述】:

我想了解git show -s --format=%H 在德威的行为;即得到完整提交哈希HEAD 指向。然而,事实证明porcelain.show() function 的行为与git show 非常相似,但似乎不知道任何其他选项,例如 Git CLI。

我并不感到惊讶,因为 porcelain.describe() 的行为类似。但是我与德威有什么替代方法可以看到满的提交HEAD 的哈希?

对于缩写 - 尽管硬编码为 7 个字符(!) - 哈希我可以使用前面提到的porcelain.describe()

【问题讨论】:

    标签: python dulwich


    【解决方案1】:

    通过咨询the code for porcelain.describe(),我们可以将各个部分拼凑起来。

    1. open_repo_closingdulwich.repo.BaseRepo class 提供了一个不错的上下文管理器,具有 contextlib.closing 行为
    2. BaseRepo.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")
      

      比我最初预期的要简单。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-29
      • 1970-01-01
      • 1970-01-01
      • 2023-03-16
      • 2021-06-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多