如何查找修改了对函数的引用的所有更改集?

时间:2011-04-14 20:32:45

标签: mercurial

我需要查找与Save()方法相关的代码的所有最近更改。我需要一个mercurial命令来查找每个变更集/文件,其中一行引用字符串“Save();”被添加或修改。

我只需更改集,我需要查看所做更改的文件。

2 个答案:

答案 0 :(得分:5)

好像你正在寻找像

这样的东西
hg grep --all 'Save();'

这应该以格式

为您提供每个文件更改
<file path>:<revision>:+ or -:<line of code changed>

--all标志对于确保获得所有引用很有用,因为默认情况下,hg在找到第一个引用(向后搜索修订列表)后停止查看文件。另请注意,您几乎肯定会想要限制您搜索的修订范围,因为这需要花费大量时间来处理大型回购。

如果你使用的是unix系统,你应该能够将grep命令的输出传输到一个文件中(运行需要一段时间,你可能想要缓存它以防万一你没有得到以后的东西正确的第一次)

cat saved_grep_results | awk 'BEGIN {FS=":"} {print $1" "$2}' | uniq

这应该为您提供要查看的文件和修订列表。

答案 1 :(得分:1)

您正在寻找hg grep。它需要一个Perl / Python正则表达式,并返回找到匹配项的文件的第一个修订版的结果。

hg grep [OPTION]... PATTERN [FILE]...

Search revisions of files for a regular expression.

This command behaves differently than Unix grep. It only accepts Python/Perl regexps. It searches repository history, not the working directory. It always prints the revision number in which a match
appears.

By default, grep only prints output for the first revision of a file in which it finds a match. To get it to print every revision that contains a change in match status ("-" for a match that becomes a non-
match, or "+" for a non-match that becomes a match), use the --all flag.

Returns 0 if a match is found, 1 otherwise.

所以在你的情况下,像

hg grep Save

至少应该是一个好的起点。