[PATCH 4 of 8] revset: added lazyset implementation to _matchfiles

Lucas Moscovicz lmoscovicz at fb.com
Tue Feb 11 15:54:42 CST 2014


# HG changeset patch
# User Lucas Moscovicz <lmoscovicz at fb.com>
# Date 1391532667 28800
#      Tue Feb 04 08:51:07 2014 -0800
# Node ID 7a047e944f639aa3663f40e4f922ec9df9eb0c82
# Parent  f34fe1564f148a4c6e70e2e0e1409f8f723cf772
revset: added lazyset implementation to _matchfiles

Performance Benchmarking:

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

real  0m2.234s
user  0m2.180s
sys 0m0.044s

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

real  0m0.172s
user  0m0.129s
sys 0m0.042s

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -857,10 +857,10 @@
             hasset = True
     if not default:
         default = 'glob'
-    m = None
-    s = []
-    for r in subset:
-        c = repo[r]
+
+    def matches(x):
+        m = None
+        c = repo[x]
         if not m or (hasset and rev is None):
             ctx = c
             if rev is not None:
@@ -869,9 +869,10 @@
                                exclude=exc, ctx=ctx, default=default)
         for f in c.files():
             if m(f):
-                s.append(r)
-                break
-    return baseset(s)
+                return True
+        return False
+
+    return lazyset(subset, matches)
 
 def hasfile(repo, subset, x):
     """``file(pattern)``


More information about the Mercurial-devel mailing list