【发布时间】:2011-12-01 14:17:18
【问题描述】:
我想在 pre-commit-hook 中检查用户名。在命令行中,我想要实现的效果如下所示:
hg log -r "$HG_NODE:tip" --template "{author}\n"
如何使用内部 Mercurial API 实现相同的功能?
【问题讨论】:
我想在 pre-commit-hook 中检查用户名。在命令行中,我想要实现的效果如下所示:
hg log -r "$HG_NODE:tip" --template "{author}\n"
如何使用内部 Mercurial API 实现相同的功能?
【问题讨论】:
假设您已经知道如何获取 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:
【讨论】: