diff mercurial/revset.py @ 35816:f6ca1e11d8b4 stable

revset: evaluate filesets against each revision for 'file()' (issue5778) After f2aeff8a87b6, the fileset was evaluated to a set of files against the working directory, and then those files were applied against each revision. The result was nonsense. For example, `hg log -r 'file("set:exec()")'` on the Mercurial repo listed revision 0 because it has the `hg` script, which is currently +x. But that bit wasn't applied until revision 280 (which 'contains()' properly indicates). This technique was borrowed from checkstatus(), which services adds(), modifies(), and removes(), so it seems safe enough. The 'r:' case is explicitly assigned to wdirrev, freeing up rev=None to mean "re-evaluate at each revision". The distinction is important to avoid behavior changes with `hg log set:...` (test-largefiles-misc.t and test-fileset-generated.t drop current log output without this). I'm not sure what the right behavior for that is (1fd352aa08fc explicitly enabled this behavior for graphlog), but the day before the release isn't the time to experiment.
author Matt Harbison <matt_harbison@yahoo.com>
date Sun, 28 Jan 2018 14:08:59 -0500
parents 134ef400cb11
children 00a56c83ab64
line wrap: on
line diff
--- a/mercurial/revset.py	Wed Jan 31 23:01:44 2018 -0500
+++ b/mercurial/revset.py	Sun Jan 28 14:08:59 2018 -0500
@@ -1065,7 +1065,9 @@
             if rev is not None:
                 raise error.ParseError('_matchfiles expected at most one '
                                        'revision')
-            if value != '': # empty means working directory; leave rev as None
+            if value == '': # empty means working directory
+                rev = node.wdirrev
+            else:
                 rev = value
         elif prefix == 'd:':
             if default is not None:
@@ -1076,9 +1078,9 @@
             raise error.ParseError('invalid _matchfiles prefix: %s' % prefix)
     if not default:
         default = 'glob'
+    hasset = any(matchmod.patkind(p) == 'set' for p in pats + inc + exc)
 
-    m = matchmod.match(repo.root, repo.getcwd(), pats, include=inc,
-                       exclude=exc, ctx=repo[rev], default=default)
+    mcache = [None]
 
     # This directly read the changelog data as creating changectx for all
     # revisions is quite expensive.
@@ -1089,6 +1091,14 @@
             files = repo[x].files()
         else:
             files = getfiles(x)
+
+        if not mcache[0] or (hasset and rev is None):
+            r = x if rev is None else rev
+            mcache[0] = matchmod.match(repo.root, repo.getcwd(), pats,
+                                       include=inc, exclude=exc, ctx=repo[r],
+                                       default=default)
+        m = mcache[0]
+
         for f in files:
             if m(f):
                 return True