4

每次我需要标准搜索之外的任何东西时,我都会尝试几件事,搜索谷歌并最终以失败告终。显然,Hg 搜索语法非常广泛,我想使用它的强大功能,但我似乎无法找到一个好的参考。

例如,我经常想在存储库中查找与部分路径匹配相关的所有更改。我知道以下工作:

file('path:full/path/file.txt')

但我想通过部分匹配搜索文件,但以下都不起作用:

jquery                  -- seems to find everything
file(jquery*)           -- finds nothing
file('jquery*')         -- finds nothing
file('path:jquery.*')   -- finds nothing
file('name:jquery.*')   -- finds nothing
file('path:jquery.js')  -- finds every revision, it seems

从 TortoiseHg 的弹出窗口中,我看到有大量选项,但没有提示如何使用它们(帮助链接显示更多,但没有关于模式应该是什么样子的内容file(pattern)):

在此处输入图像描述

最后我通常会使用其他搜索方式找到我想要的东西,但能够使用这种表达能力真是太好了,可惜这么多年了,我从来没有发现如何利用这一点。

4

1 回答 1

5

我非常建议为此使用 hg 帮助系统。最有用的页面(在我看来):

hg help revsets
hg help filesets
hg help patterns

在有关模式的页面中,您可以找到有关“路径:”的信息:

To use a plain path name without any pattern matching, start it with
"path:". These path names must completely match starting at the current
repository root.

换句话说:使用 'path:' 不适合这个目的。稍微在下面,提到了“glob:”:

To use an extended glob, start a name with "glob:". Globs are rooted at
the current directory; a glob such as "*.c" will only match files in the
current directory ending with ".c".

The supported glob syntax extensions are "**" to match any string across
path separators and "{a,b}" to mean "a or b".

换句话说,应该可以使用该模式file('glob:**jquery*')。事实上,上面的模式在没有 glob 前缀的情况下也可以工作,所以:file('**jquery*'). 请参阅有关修订集的部分页面:

  "file(pattern)"
  Changesets affecting files matched by pattern.

  For a faster but less accurate result, consider using "filelog()"
  instead.

  This predicate uses "glob:" as the default kind of pattern.
于 2015-06-10T06:40:02.667 回答