开发者

How do I get a list of changesets between two revisions using the internal Mercurial API?

开发者 https://www.devze.com 2023-04-11 12:45 出处:网络
I want to check the user names in a pre-commit-hook. From the command line, what I want to achieve looks like this:

I want to check the user names in a pre-commit-hook. From the command line, what I want to achieve looks like this:

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

How do I achieve the 开发者_如何学运维same using the internal Mercurial API?


Presuming you've already figured out how to get a repo object, with the stable release you can do:

start = repo[node].rev()
end = repo['tip'].rev()

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

In the development branch, you can do this:

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

Also note that 'node::tip' (two colons) might be a more useful definition of 'between': it includes all descendants of node and all ancestors of tip, rather than simply numerical ordering.

Lastly, make sure you've read all the caveats about using the internal API here:

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

...and consider using python-hglib instead:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号