Mercurial 是否有模板来捕获 "hg grep" 的输出?

Does Mercurial have a template to capture output of "hg grep"?

我正在搜索包含 "foreach" 的更改,所以我使用了这个 Mercurial 命令:

$ hg grep -r "user(mjh) & public() & date(-30)" --diff -i foreach

它会 return 添加和删除 "foreach" 的命中。

不过,我也想知道实际的提交哈希值。如果我添加一个模板:

$ hg grep ... -T '{date|shortdate}\n{node|short}\n{desc|firstline}\n\n'

然后我得到了预期的提交哈希和描述,但是我没有看到列出的更改文件。

是否有捕获hg grep输出的模板? {files} 模板列出了与提交关联的文件,但这不是实际的 grep 输出。是否有可用于 grep 结果的可迭代模板关键字?

  1. 请仔细阅读hg help grep -v(-v 是重要的选项),注意以下部分(新的和对我来说 意外)

The following keywords are supported in addition to the common template keywords and functions. See also 'hg help templates'.

change        String. Character denoting insertion "+" or removal "-".
              Available if "--diff" is specified.
lineno        Integer. Line number of the match.
path          String. Repository-absolute path of the file.
texts         List of text chunks.

之后你就可以重复(马马虎虎,因为一些细节会略有不同)模板中 grep 的默认输出

>hg grep --diff -i -r 1166 to_try

>hg grep --diff -i -r 1166 -T "{path}:{rev}:{change}:{texts}\n" to_try

hggit/compat.py:1166:-:    for args in parameters_to_try:
hggit/compat.py:1166:+:    for (args, kwargs) in parameters_to_try:

并在将 {rev} 替换为 {node|short}

之后
>hg grep --diff -i -r 1166 -T "{path}:{node|short}:{change}:{texts}\n" to_try
hggit/compat.py:f6cef55e6aeb:-:    for args in parameters_to_try:
hggit/compat.py:f6cef55e6aeb:+:    for (args, kwargs) in parameters_to_try: