[PATCH 2 of 9 RFC] revset: added ordered generatorsets with cached contains method

Lucas Moscovicz lmoscovicz at fb.com
Wed Feb 12 16:39:52 CST 2014


# HG changeset patch
# User Lucas Moscovicz <lmoscovicz at fb.com>
# Date 1391796950 28800
#      Fri Feb 07 10:15:50 2014 -0800
# Node ID 9a72b9c402c56b5d23f2aa85b681a287c93201d2
# Parent  31c4cb808b0c3fc6484ecde3be2c9f0bcd5cad0a
revset: added ordered generatorsets with cached contains method

They behave similar to the generatorset but since they have an order they can
return faster when asked for revisions not included.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2180,6 +2180,50 @@
     def set(self):
         return self
 
+class ascgeneratorset(generatorset):
+    def __contains__(self, x):
+        if x in self._pcache:
+            return True
+        if x in self._ncache:
+            return False
+
+        while True:
+            try:
+                l = self._iter.next()
+                self._pcache.add(l)
+                if l == x:
+                    return True
+                if l > x:
+                    self._ncache.add(x)
+                    return False
+            except (StopIteration):
+                break
+
+        self._ncache.add(x)
+        return False
+
+class descgeneratorset(generatorset):
+    def __contains__(self, x):
+        if x in self._pcache:
+            return True
+        if x in self._ncache:
+            return False
+
+        while True:
+            try:
+                l = self._iter.next()
+                self._pcache.add(l)
+                if l == x:
+                    return True
+                if l < x:
+                    self._ncache.add(x)
+                    return False
+            except (StopIteration):
+                break
+
+        self._ncache.add(x)
+        return False
+
 class spanset(object):
     """Duck type for baseset class which represents a range of revisions and
     can work lazily and without having all the range in memory


More information about the Mercurial-devel mailing list