[PATCH 4 of 4] revset: added intersection to baseset class

Lucas Moscovicz lmoscovicz at fb.com
Mon Feb 3 13:44:35 CST 2014


# HG changeset patch
# User Lucas Moscovicz <lmoscovicz at fb.com>
# Date 1390611464 28800
#      Fri Jan 24 16:57:44 2014 -0800
# Node ID c7a2e2891d64dc826a305983e14b678cb922f97b
# Parent  f6b40a0e62bbdcfc8aaa10f0b678428809a8c729
revset: added intersection to baseset class

Added the method __and__ to the baseset class to be able to intersect with
other objects in a more efficient way.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -402,8 +402,7 @@
             bmrevs = set()
             for bmrev in matchrevs:
                 bmrevs.add(repo[bmrev].rev())
-            s = subset.set()
-            return baseset([r for r in s if r in bmrevs])
+            return subset & bmrevs
 
     bms = set([repo[r].rev()
                for r in repo._bookmarks.values()])
@@ -450,7 +449,7 @@
     # i18n: "bumped" is a keyword
     getargs(x, 0, 0, _("bumped takes no arguments"))
     bumped = obsmod.getrevs(repo, 'bumped')
-    return baseset([r for r in subset if r in bumped])
+    return subset & bumped
 
 def bundle(repo, subset, x):
     """``bundle()``
@@ -462,7 +461,7 @@
         bundlerevs = repo.changelog.bundlerevs
     except AttributeError:
         raise util.Abort(_("no bundle provided - specify with -R"))
-    return baseset([r for r in subset if r in bundlerevs])
+    return subset & bundlerevs
 
 def checkstatus(repo, subset, pat, field):
     m = None
@@ -515,7 +514,7 @@
     """
     s = getset(repo, baseset(repo), x).set()
     cs = _children(repo, subset, s)
-    return baseset([r for r in subset if r in cs])
+    return subset & cs
 
 def closed(repo, subset, x):
     """``closed()``
@@ -680,7 +679,7 @@
     # i18n: "extinct" is a keyword
     getargs(x, 0, 0, _("extinct takes no arguments"))
     extincts = obsmod.getrevs(repo, 'extinct')
-    return baseset([r for r in subset if r in extincts])
+    return subset & extincts
 
 def extra(repo, subset, x):
     """``extra(label, [value])``
@@ -906,7 +905,7 @@
     # i18n: "hidden" is a keyword
     getargs(x, 0, 0, _("hidden takes no arguments"))
     hiddenrevs = repoview.filterrevs(repo, 'visible')
-    return baseset([r for r in subset if r in hiddenrevs])
+    return subset & hiddenrevs
 
 def keyword(repo, subset, x):
     """``keyword(string)``
@@ -1039,7 +1038,7 @@
     # i18n: "obsolete" is a keyword
     getargs(x, 0, 0, _("obsolete takes no arguments"))
     obsoletes = obsmod.getrevs(repo, 'obsolete')
-    return baseset([r for r in subset if r in obsoletes])
+    return subset & obsoletes
 
 def origin(repo, subset, x):
     """``origin([set])``
@@ -1106,8 +1105,7 @@
     cl = repo.changelog
     for r in getset(repo, baseset(repo), x):
         ps.add(cl.parentrevs(r)[0])
-    s = subset.set()
-    return baseset([r for r in s if r in ps])
+    return subset & ps
 
 def p2(repo, subset, x):
     """``p2([set])``
@@ -1125,8 +1123,7 @@
     cl = repo.changelog
     for r in getset(repo, baseset(repo), x):
         ps.add(cl.parentrevs(r)[1])
-    s = subset.set()
-    return baseset([r for r in s if r in ps])
+    return subset & ps
 
 def parents(repo, subset, x):
     """``parents([set])``
@@ -1134,14 +1131,13 @@
     """
     if x is None:
         ps = tuple(p.rev() for p in repo[x].parents())
-        return baseset([r for r in subset if r in ps])
+        return subset & ps
 
     ps = set()
     cl = repo.changelog
     for r in getset(repo, baseset(repo), x):
         ps.update(cl.parentrevs(r))
-    s = subset.set()
-    return baseset([r for r in s if r in ps])
+    return subset & ps
 
 def parentspec(repo, subset, x, n):
     """``set^0``
@@ -1166,8 +1162,7 @@
             parents = cl.parentrevs(r)
             if len(parents) > 1:
                 ps.add(parents[1])
-    s = subset.set()
-    return baseset([r for r in s if r in ps])
+    return subset & ps
 
 def present(repo, subset, x):
     """``present(set)``
@@ -1508,7 +1503,7 @@
             s = set([cl.rev(n) for t, n in repo.tagslist() if matcher(t)])
     else:
         s = set([cl.rev(n) for t, n in repo.tagslist() if t != 'tip'])
-    return baseset([r for r in subset if r in s])
+    return subset & s
 
 def tagged(repo, subset, x):
     return tag(repo, subset, x)
@@ -1520,7 +1515,7 @@
     # i18n: "unstable" is a keyword
     getargs(x, 0, 0, _("unstable takes no arguments"))
     unstables = obsmod.getrevs(repo, 'unstable')
-    return baseset([r for r in subset if r in unstables])
+    return subset & unstables
 
 
 def user(repo, subset, x):
@@ -2051,5 +2046,11 @@
             s = set(x)
         return baseset(self.set() - s)
 
+    def __and__(self, x):
+        s = self.set()
+        if isinstance(x, baseset):
+            x = x.set()
+        return baseset([y for y in s if y in x])
+
 # tell hggettext to extract docstrings from these functions:
 i18nfunctions = symbols.values()


More information about the Mercurial-devel mailing list