revset: fix adds/modifies/removes and patterns (
issue3403)
The fast path was triggered if the argument was not like "type:value", with
type a known pattern type. This is wrong for several reasons:
- path:value is valid for the fast path
- '*' is interpreted as a glob by default and is not valid for fast path
Fast path detection is now done after the pattern is parsed, and the normalized
path is extracted for direct comparison. All this seems a bit complicated, it
is tempting to drop the fast path completely. Also, the hasfile() revset does
something similar (only check .files()), without a fast path. If the fast path
is really that efficient maybe it should be used there too.
Note that:
$ log 'modifies("set:modified()")'
is different from:
$ log 'modifies("*")'
because of the usual merge ctx.files()/status(ctx.p1(), ctx) differences.
Reported by Steffen Eichenberg <steffen.eichenberg@msg-gillardon.de>
--- a/mercurial/revset.py Thu Apr 26 13:18:47 2012 -0500
+++ b/mercurial/revset.py Thu Apr 26 14:24:46 2012 +0200
@@ -341,23 +341,26 @@
def checkstatus(repo, subset, pat, field):
m = None
s = []
- fast = not matchmod.patkind(pat)
+ hasset = matchmod.patkind(pat) == 'set'
+ fname = None
for r in subset:
c = repo[r]
- if fast:
- if pat not in c.files():
+ if not m or hasset:
+ m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c)
+ if not m.anypats() and len(m.files()) == 1:
+ fname = m.files()[0]
+ if fname is not None:
+ if fname not in c.files():
continue
else:
- if not m or matchmod.patkind(pat) == 'set':
- m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c)
for f in c.files():
if m(f):
break
else:
continue
files = repo.status(c.p1().node(), c.node())[field]
- if fast:
- if pat in files:
+ if fname is not None:
+ if fname in files:
s.append(r)
else:
for f in files:
--- a/tests/test-revset.t Thu Apr 26 13:18:47 2012 -0500
+++ b/tests/test-revset.t Thu Apr 26 14:24:46 2012 +0200
@@ -305,6 +305,13 @@
6
$ log 'modifies(b)'
4
+ $ log 'modifies("path:b")'
+ 4
+ $ log 'modifies("*")'
+ 4
+ 6
+ $ log 'modifies("set:modified()")'
+ 4
$ log 'id(5)'
2
$ log 'outgoing()'