[PATCH 3 of 4] revset: added substraction to baseset class

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


# HG changeset patch
# User Lucas Moscovicz <lmoscovicz at fb.com>
# Date 1390515658 28800
#      Thu Jan 23 14:20:58 2014 -0800
# Node ID f6b40a0e62bbdcfc8aaa10f0b678428809a8c729
# Parent  6787b6222593319d57225527030e68ab54bc3350
revset: added substraction to baseset class

Added __sub__ method to the baseset class to be able to compare it with other
subsets more efficiently.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -248,13 +248,11 @@
 
 def orset(repo, subset, x, y):
     xl = getset(repo, subset, x)
-    s = xl.set()
-    yl = getset(repo, baseset([r for r in subset if r not in s]), y)
+    yl = getset(repo, subset - xl, y)
     return baseset(xl + yl)
 
 def notset(repo, subset, x):
-    s = getset(repo, subset, x).set()
-    return baseset([r for r in subset if r not in s])
+    return subset - getset(repo, subset, x)
 
 def listset(repo, subset, a, b):
     raise error.ParseError(_("can't use a list in this context"))
@@ -897,9 +895,9 @@
     """``heads(set)``
     Members of set with no children in set.
     """
-    s = getset(repo, subset, x).set()
-    ps = parents(repo, subset, x).set()
-    return baseset([r for r in s if r not in ps])
+    s = getset(repo, subset, x)
+    ps = parents(repo, subset, x)
+    return s - ps
 
 def hidden(repo, subset, x):
     """``hidden()``
@@ -1377,7 +1375,7 @@
     s = getset(repo, baseset(repo.changelog), x).set()
     subset = baseset([r for r in subset if r in s])
     cs = _children(repo, subset, s)
-    return baseset([r for r in subset if r not in cs])
+    return subset - cs
 
 def secret(repo, subset, x):
     """``secret()``
@@ -2046,5 +2044,12 @@
             self._set = set(self)
         return self._set
 
+    def __sub__(self, x):
+        if isinstance(x, baseset):
+            s = x.set()
+        else:
+            s = set(x)
+        return baseset(self.set() - s)
+
 # tell hggettext to extract docstrings from these functions:
 i18nfunctions = symbols.values()


More information about the Mercurial-devel mailing list