Patchwork [5,of,8] revset: added lazyset implementation to grep revset

login
register
mail settings
Submitter Lucas Moscovicz
Date Feb. 11, 2014, 8:55 p.m.
Message ID <e83543ce7069828b0271.1392152120@dev1037.prn2.facebook.com>
Download mbox | patch
Permalink /patch/3576/
State Accepted
Commit 6aa7dcae6bd835be3f6a0daa8ebd9a9a556b137e
Headers show

Comments

Lucas Moscovicz - Feb. 11, 2014, 8:55 p.m.
# HG changeset patch
# User Lucas Moscovicz <lmoscovicz@fb.com>
# Date 1391126598 28800
#      Thu Jan 30 16:03:18 2014 -0800
# Node ID e83543ce7069828b0271f798b68fd682f8174c03
# Parent  336524e10809d78981001dda5465295b7d312109
revset: added lazyset implementation to grep revset

Performance benchmarking:

$ time hg log -qr "first(grep(hg))"
0:9117c6561b0b

real  0m2.214s
user  0m2.163s
sys 0m0.045s

$ time ./hg log -qr "first(grep(hg))"
0:9117c6561b0b

real  0m0.211s
user  0m0.146s
sys 0m0.035s

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -800,14 +800,15 @@ 
         gr = re.compile(getstring(x, _("grep requires a string")))
     except re.error, e:
         raise error.ParseError(_('invalid match pattern: %s') % e)
-    l = []
-    for r in subset:
-        c = repo[r]
+
+    def matches(x):
+        c = repo[x]
         for e in c.files() + [c.user(), c.description()]:
             if gr.search(e):
-                l.append(r)
-                break
-    return baseset(l)
+                return True
+        return False
+
+    return lazyset(subset, matches)
 
 def _matchfiles(repo, subset, x):
     # _matchfiles takes a revset list of prefixed arguments: