Searching for the change history of partial file or path in Mercurial or TortoiseHg

296 views Asked by At

Each time I need anything beyond the standard search, I find myself trying several things, searching Google and in the end terribly failing. Apparently, the Hg search syntax is pretty extensive and I would like to use its power, but I don't seem to be able to find a good reference.

For instance, quite often I want to find all changes in the repository related to a partial path match. I know that the following works:

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

But I would like to search for files by partial match, and neither of the following worked:

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

From the popup in TortoiseHg I see that there are a gazillion options, but no hint on how to use them (the help link shows a little bit more, but nothing on what a pattern should look like in file(pattern)):

enter image description here

In the end I usually find what I want using other ways of searching, but it would be so nice to be able to use this power of expression, and it's quite a shame that after so many years, I've never found out how to leverage this.

1

There are 1 answers

1
Mathiasdm On BEST ANSWER

I can very much advise using the hg help system for this. The most useful pages to look at (in my view):

hg help revsets
hg help filesets
hg help patterns

In the page about patterns, you can find about 'path:':

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.

In other words: using 'path:' is not suitable for this purpose. Slightly below, 'glob:' is mentioned:

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".

In other words, it should be possible to use the pattern file('glob:**jquery*'). In fact, the above pattern would also work without the glob prefix, so: file('**jquery*'). See part of the page about revsets:

  "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.