【问题标题】:How do I get a list of changesets between two revisions using the internal Mercurial API?如何使用内部 Mercurial API 获取两个修订版之间的变更集列表?
【发布时间】:2011-12-01 14:17:18
【问题描述】:

我想在 pre-commit-hook 中检查用户名。在命令行中,我想要实现的效果如下所示:

hg log -r "$HG_NODE:tip" --template "{author}\n"

如何使用内部 Mercurial API 实现相同的功能?

【问题讨论】:

    标签: mercurial pre-commit-hook


    【解决方案1】:

    假设您已经知道如何获取 repo 对象,您可以使用稳定版本:

    start = repo[node].rev()
    end = repo['tip'].rev()
    
    for r in xrange(start, end + 1):
        ctx = repo[r]
        print ctx.user()
    

    在开发分支中,你可以这样做:

    for ctx in repo.set('%s:tip', node): # node here must be hex, use %n for binary
        print ctx.user()
    

    另请注意,“node::tip”(两个冒号)可能是“between”更有用的定义:它包括 node 的所有后代和 tip 的所有祖先,而不是简单的数字排序。

    最后,请确保您已阅读此处关于使用内部 API 的所有注意事项:

    https://www.mercurial-scm.org/wiki/MercurialApi

    ...并考虑改用 python-hglib:

    https://www.mercurial-scm.org/wiki/CommandServer

    【讨论】:

    • 好吧,我想要在节点之后添加的所有变更集(包括)。所以实际上我需要严格的数字排序。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-27
    • 2013-07-08
    • 1970-01-01
    • 2015-07-08
    • 1970-01-01
    • 2011-08-28
    • 1970-01-01
    相关资源
    最近更新 更多