【问题标题】:How to get the revision history between particular time frame or after a certain revision or commit id upto the latest using Mercurial API?如何使用 Mercurial API 获取特定时间范围之间或某个修订或提交 id 之后的修订历史记录?
【发布时间】:2011-12-15 07:00:52
【问题描述】:

我想在特定的提交 ID 或时间之后获取所有提交及其变更集。有没有使用 Mercurial API 的直接方法?

【问题讨论】:

    标签: mercurial logging dvcs mercurial-hook


    【解决方案1】:

    您可能知道,Mercurial 有 no stable Python-level API。命令行实际上是唯一受支持的 API(除非您使用像 JavaHgpython-hglib 这样的包装库)。

    所以你会在命令行上运行

    $ hg log -r "ID::"
    

    获取ID 之后的所有变更集。 :: 运算符为您提供后代,如果您只是想要具有更高修订号的变更集,请使用 ID:,即使它们不是 ID 的后代。

    使用 JavaHg,您将实例化一个 Repository 对象并使用 LogCommand

    List<Changeset> changesets = LogCommand.on(repo).rev(id + "::").execute();
    

    然后您可以遍历changesets 列表。使用 python-hglib 它看起来像

    changesets = client.log(id + "::")
    

    最后,如果你直接导入 Mercurial 代码就可以了

    ctxs = repo.set(id + "::")
    

    获取产生changectx 对象的迭代器。虽然我们不保证 Python API,但我希望它也非常稳定。

    上面的重点是通过变更集 ID 或修订号进行查找。如果你想按日期查找,那么你需要调用相当于

    $ hg log -d '>YOUR-DATE'
    

    在 JavaHg 中,您可以在 LogCommand 上使用 date(String date) 方法,在 python-hglib 中设置 date 关键字参数,在内部使用 date revset 谓词 - 参见 hg help revsets

    【讨论】:

      猜你喜欢
      • 2013-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多