Patchwork [7,of,8] revset: added lazyset implementation to contains revset

login
register
mail settings
Submitter Lucas Moscovicz
Date Feb. 11, 2014, 9:54 p.m.
Message ID <b0e722dad1f01c16cfda.1392155685@dev1037.prn2.facebook.com>
Download mbox | patch
Permalink /patch/3595/
State Accepted
Commit abd8e56a1038b938fe6da1b3408b6ca245877ccd
Headers show

Comments

Lucas Moscovicz - Feb. 11, 2014, 9:54 p.m.
# HG changeset patch
# User Lucas Moscovicz <lmoscovicz@fb.com>
# Date 1391555223 28800
#      Tue Feb 04 15:07:03 2014 -0800
# Node ID b0e722dad1f01c16cfda70a30e8b22238ef88976
# Parent  af218c860f211d0854f682fa6a728cd9debccee4
revset: added lazyset implementation to contains revset

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -535,23 +535,21 @@ 
     """
     # i18n: "contains" is a keyword
     pat = getstring(x, _("contains requires a pattern"))
-    s = []
-    if not matchmod.patkind(pat):
-        pat = pathutil.canonpath(repo.root, repo.getcwd(), pat)
-        for r in subset:
-            if pat in repo[r]:
-                s.append(r)
-    else:
-        m = None
-        for r in subset:
-            c = repo[r]
-            if not m or matchmod.patkind(pat) == 'set':
-                m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c)
+
+    def matches(x):
+        if not matchmod.patkind(pat):
+            pats = pathutil.canonpath(repo.root, repo.getcwd(), pat)
+            if pats in repo[x]:
+                return True
+        else:
+            c = repo[x]
+            m = matchmod.match(repo.root, repo.getcwd(), [pat], ctx=c)
             for f in c.manifest():
                 if m(f):
-                    s.append(r)
-                    break
-    return baseset(s)
+                    return True
+        return False
+
+    return lazyset(subset, matches)
 
 def converted(repo, subset, x):
     """``converted([id])``