changeset 15964:6e37b8282aa2 stable

revsets: provide contexts for filesets Before this change, revsets containing fileset patterns failed. This allows queries like: hg log -r "contains('set: added() and symlink()')"
author Matt Mackall <mpm@selenic.com>
date Fri, 20 Jan 2012 23:05:04 -0600
parents 042e84e39dee
children 57738b9130ae
files mercurial/revset.py
diffstat 1 files changed, 18 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Fri Jan 20 22:19:40 2012 -0600
+++ b/mercurial/revset.py	Fri Jan 20 23:05:04 2012 -0600
@@ -296,15 +296,17 @@
     return [r for r in subset if r in s or repo[r].branch() in b]
 
 def checkstatus(repo, subset, pat, field):
-    m = matchmod.match(repo.root, repo.getcwd(), [pat])
+    m = None
     s = []
-    fast = (m.files() == [pat])
+    fast = not matchmod.patkind(pat)
     for r in subset:
         c = repo[r]
         if fast:
             if pat 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
@@ -354,15 +356,18 @@
     """
     # i18n: "contains" is a keyword
     pat = getstring(x, _("contains requires a pattern"))
-    m = matchmod.match(repo.root, repo.getcwd(), [pat])
+    m = None
     s = []
-    if m.files() == [pat]:
+    if not matchmod.patkind(pat):
         for r in subset:
             if pat in repo[r]:
                 s.append(r)
     else:
         for r in subset:
-            for f in repo[r].manifest():
+            c = repo[r]
+            if not m or matchmod.patkind(pat) == 'set':
+                m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c)
+            for f in c.manifest():
                 if m(f):
                     s.append(r)
                     break
@@ -412,10 +417,11 @@
     """
 
     pat = getstring(x, _("filelog requires a pattern"))
-    m = matchmod.match(repo.root, repo.getcwd(), [pat], default='relpath')
+    m = matchmod.match(repo.root, repo.getcwd(), [pat], default='relpath',
+                       ctx=repo[None])
     s = set()
 
-    if not m.anypats():
+    if not matchmod.patkind(pat):
         for f in m.files():
             fl = repo.file(f)
             for fr in fl:
@@ -500,10 +506,13 @@
     """
     # i18n: "file" is a keyword
     pat = getstring(x, _("file requires a pattern"))
-    m = matchmod.match(repo.root, repo.getcwd(), [pat])
+    m = None
     s = []
     for r in subset:
-        for f in repo[r].files():
+        c = repo[r]
+        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):
                 s.append(r)
                 break