Patchwork [5,of,9,RFC] revset: changed revset code to use filter method

login
register
mail settings
Submitter Lucas Moscovicz
Date Feb. 12, 2014, 10:39 p.m.
Message ID <1c8171087d53c930aee3.1392244795@dev1037.prn2.facebook.com>
Download mbox | patch
Permalink /patch/3625/
State Superseded
Headers show

Comments

Lucas Moscovicz - Feb. 12, 2014, 10:39 p.m.
# HG changeset patch
# User Lucas Moscovicz <lmoscovicz@fb.com>
# Date 1391707721 28800
#      Thu Feb 06 09:28:41 2014 -0800
# Node ID 1c8171087d53c930aee31fb53701bb1fb66341f0
# Parent  020b11eeee89ad970bce64312232325428b1d3b1
revset: changed revset code to use filter method

Revset methods now use the filter code to apply a condition.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -310,7 +310,7 @@ 
     if not args:
         return baseset([])
     s = set(_revancestors(repo, args, followfirst)) | set(args)
-    return baseset([r for r in subset if r in s])
+    return subset.filter(lambda r: r in s)
 
 def ancestors(repo, subset, x):
     """``ancestors(set)``
@@ -338,7 +338,7 @@ 
         for i in range(n):
             r = cl.parentrevs(r)[0]
         ps.add(r)
-    return baseset([r for r in subset if r in ps])
+    return subset.filter(lambda r: r in ps)
 
 def author(repo, subset, x):
     """``author(string)``
@@ -347,7 +347,7 @@ 
     # i18n: "author" is a keyword
     n = encoding.lower(getstring(x, _("author requires a string")))
     kind, pattern, matcher = _substringmatcher(n)
-    return lazyset(subset, lambda x: matcher(encoding.lower(repo[x].user())))
+    return subset.filter(lambda x: matcher(encoding.lower(repo[x].user())))
 
 def bisect(repo, subset, x):
     """``bisect(string)``
@@ -391,7 +391,7 @@ 
             if not bmrev:
                 raise util.Abort(_("bookmark '%s' does not exist") % bm)
             bmrev = repo[bmrev].rev()
-            return lazyset(subset, lambda r: r == bmrev)
+            return subset.filter(lambda r: r == bmrev)
         else:
             matchrevs = set()
             for name, bmrev in repo._bookmarks.iteritems():
@@ -407,7 +407,7 @@ 
 
     bms = set([repo[r].rev()
                for r in repo._bookmarks.values()])
-    return lazyset(subset, lambda r: r in bms)
+    return subset.filter(lambda r: r in bms)
 
 def branch(repo, subset, x):
     """``branch(string or set)``
@@ -429,9 +429,9 @@ 
             # note: falls through to the revspec case if no branch with
             # this name exists
             if pattern in repo.branchmap():
-                return lazyset(subset, lambda r: matcher(repo[r].branch()))
+                return subset.filter(lambda r: matcher(repo[r].branch()))
         else:
-            return lazyset(subset, lambda r: matcher(repo[r].branch()))
+            return subset.filter(lambda r: matcher(repo[r].branch()))
 
     s = getset(repo, spanset(0, len(repo), repo.changelog.filteredrevs),
                 x)
@@ -439,7 +439,7 @@ 
     for r in s:
         b.add(repo[r].branch())
     s = s.set()
-    return lazyset(subset, lambda r: r in s or repo[r].branch() in b)
+    return subset.filter(lambda r: r in s or repo[r].branch() in b)
 
 def bumped(repo, subset, x):
     """``bumped()``
@@ -493,7 +493,7 @@ 
                 if m(f):
                     return True
 
-    return lazyset(subset, matches)
+    return subset.filter(matches)
 
 def _children(repo, narrow, parentset):
     cs = set()
@@ -523,7 +523,7 @@ 
     """
     # i18n: "closed" is a keyword
     getargs(x, 0, 0, _("closed takes no arguments"))
-    return lazyset(subset, lambda r: repo[r].closesbranch())
+    return subset.filter(lambda r: repo[r].closesbranch())
 
 def contains(repo, subset, x):
     """``contains(pattern)``
@@ -550,7 +550,7 @@ 
                     return True
         return False
 
-    return lazyset(subset, matches)
+    return subset.filter(matches)
 
 def converted(repo, subset, x):
     """``converted([id])``
@@ -572,7 +572,7 @@ 
         source = repo[r].extra().get('convert_revision', None)
         return source is not None and (rev is None or source.startswith(rev))
 
-    return lazyset(subset, lambda r: _matchvalue(r))
+    return subset.filter(lambda r: _matchvalue(r))
 
 def date(repo, subset, x):
     """``date(interval)``
@@ -581,7 +581,7 @@ 
     # i18n: "date" is a keyword
     ds = getstring(x, _("date requires a string"))
     dm = util.matchdate(ds)
-    return lazyset(subset, lambda x: dm(repo[x].date()[0]))
+    return subset.filter(lambda x: dm(repo[x].date()[0]))
 
 def desc(repo, subset, x):
     """``desc(string)``
@@ -594,7 +594,7 @@ 
         c = repo[x]
         return ds in encoding.lower(c.description())
 
-    return lazyset(subset, matches)
+    return subset.filter(matches)
 
 def _descendants(repo, subset, x, followfirst=False):
     args = getset(repo, spanset(0, len(repo),
@@ -659,7 +659,7 @@ 
             r = src
             src = _getrevsource(repo, r)
 
-    return baseset([r for r in subset if r in dests])
+    return subset.filter(lambda r: r in dests)
 
 def divergent(repo, subset, x):
     """``divergent()``
@@ -668,7 +668,7 @@ 
     # i18n: "divergent" is a keyword
     getargs(x, 0, 0, _("divergent takes no arguments"))
     divergent = obsmod.getrevs(repo, 'divergent')
-    return lazyset(subset, lambda r: r in divergent)
+    return subset.filter(lambda r: r in divergent)
 
 def draft(repo, subset, x):
     """``draft()``
@@ -676,7 +676,7 @@ 
     # i18n: "draft" is a keyword
     getargs(x, 0, 0, _("draft takes no arguments"))
     pc = repo._phasecache
-    return lazyset(subset, lambda r: pc.phase(repo, r) == phases.draft)
+    return subset.filter(lambda r: pc.phase(repo, r) == phases.draft)
 
 def extinct(repo, subset, x):
     """``extinct()``
@@ -712,7 +712,7 @@ 
         extra = repo[r].extra()
         return label in extra and (value is None or matcher(extra[label]))
 
-    return lazyset(subset, lambda r: _matchvalue(r))
+    return subset.filter(lambda r: _matchvalue(r))
 
 def filelog(repo, subset, x):
     """``filelog(pattern)``
@@ -810,7 +810,7 @@ 
                 return True
         return False
 
-    return lazyset(subset, matches)
+    return subset.filter(matches)
 
 def _matchfiles(repo, subset, x):
     # _matchfiles takes a revset list of prefixed arguments:
@@ -874,7 +874,7 @@ 
                 return True
         return False
 
-    return lazyset(subset, matches)
+    return subset.filter(matches)
 
 def hasfile(repo, subset, x):
     """``file(pattern)``
@@ -930,7 +930,7 @@ 
         return util.any(kw in encoding.lower(t) for t in c.files() + [c.user(),
             c.description()])
 
-    return lazyset(subset, matches)
+    return subset.filter(matches)
 
 def limit(repo, subset, x):
     """``limit(set, [n])``
@@ -998,7 +998,7 @@ 
     # i18n: "merge" is a keyword
     getargs(x, 0, 0, _("merge takes no arguments"))
     cl = repo.changelog
-    return lazyset(subset, lambda r: cl.parentrevs(r)[1] != -1)
+    return subset.filter(lambda r: cl.parentrevs(r)[1] != -1)
 
 def branchpoint(repo, subset, x):
     """``branchpoint()``
@@ -1015,7 +1015,7 @@ 
         for p in cl.parentrevs(r):
             if p >= baserev:
                 parentscount[p - baserev] += 1
-    return baseset([r for r in subset if (parentscount[r - baserev] > 1)])
+    return subset.filter(lambda r: parentscount[r - baserev] > 1)
 
 def minrev(repo, subset, x):
     """``min(set)``
@@ -1095,7 +1095,7 @@ 
             src = prev
 
     o = set([_firstsrc(r) for r in args])
-    return baseset([r for r in subset if r in o])
+    return subset.filter(lambda r: r in o)
 
 def outgoing(repo, subset, x):
     """``outgoing([path])``
@@ -1118,7 +1118,7 @@ 
     repo.ui.popbuffer()
     cl = repo.changelog
     o = set([cl.rev(r) for r in outgoing.missing])
-    return baseset([r for r in subset if r in o])
+    return subset.filter(lambda r: r in o)
 
 def p1(repo, subset, x):
     """``p1([set])``
@@ -1214,7 +1214,7 @@ 
     # i18n: "public" is a keyword
     getargs(x, 0, 0, _("public takes no arguments"))
     pc = repo._phasecache
-    return lazyset(subset, lambda r: pc.phase(repo, r) == phases.public)
+    return subset.filter(lambda r: pc.phase(repo, r) == phases.public)
 
 def remote(repo, subset, x):
     """``remote([id [,path]])``
@@ -1387,7 +1387,7 @@ 
                 return True
         return False
 
-    return lazyset(subset, matches)
+    return subset.filter(matches)
 
 def reverse(repo, subset, x):
     """``reverse(set)``
@@ -1412,7 +1412,7 @@ 
     # i18n: "secret" is a keyword
     getargs(x, 0, 0, _("secret takes no arguments"))
     pc = repo._phasecache
-    return lazyset(subset, lambda x: pc.phase(repo, x) == phases.secret)
+    return subset.filter(lambda x: pc.phase(repo, x) == phases.secret)
 
 def sort(repo, subset, x):
     """``sort(set[, [-]key...])``