我有一个包含多个用户的代码库。我需要编写一个Python脚本来检索特定用户的最新提交记录。如何使用Mercurial实现这一目标?
我的想法是通过Python的subprocess调用来调用hg log
命令。问题在于,我应该如何调用hg log
命令,以便告诉我一个用户的最新日志。
简单(但不高效或优雅的方式)
hg log -u 用户名
或者(使用revsets)
hg log -r "author(用户名)"
增加了价值
如果字符串以“re:”开头,则剩余部分将被视为正则表达式。要匹配实际包含“re:”的用户,请使用前缀“literal:”。
-l
选项(或limit()/last()
revset函数)。 - Tim Delaney$ hg log -u your-user-name | head -5
head -5
命令会为最新的 changeset,也就是你的用户名下的 changeset,提供整个缩略版 hg log
输出,包括五行内容:changeset、tag、user、date 和 summary。如果只需要 changeset,可以使用以下命令(同样适用于命令行版本)。
$ hg log -u mike@fontling.com | head -1 | awk '{print $2}'
评论指出这对输出格式做出了不必要的假设。我同意。
hg log -r "last(author('email@domain.com'))"
hg log -r "last(author('Fred Flintstone'))"
hg log -r "last(author('email@domain.com'), 3)"
hg log -r "last(author('Fred Flintstone'), 3)"
hg help log
、hg help revsets
和hg help templates
。 - Tim Delaneyps aux
这样的方式暴露敏感信息,或者像蟑螂一样侵入文件系统,或者打开安全漏洞的东西。而我写的则是对输出格式做出了不必要的假设。 - Mike Sherrill 'Cat Recall'