[PATCH 1 of 3] revset: added spanset class to represent revision ranges

Lucas Moscovicz lmoscovicz at fb.com
Wed Feb 12 15:54:49 CST 2014


# HG changeset patch
# User Lucas Moscovicz <lmoscovicz at fb.com>
# Date 1392228981 28800
#      Wed Feb 12 10:16:21 2014 -0800
# Node ID 70cafa9cc41d0463146b3f746b119bf89cc1f80e
# Parent  73fe61ef8bf1be6581d7b66489cfaa8335605aff
revset: added spanset class to represent revision ranges

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2128,5 +2128,25 @@
     def set(self):
         return set([r for r in self])
 
+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
+    """
+    def __init__(self, start, end):
+        self._start = start
+        self._end = end
+
+    def __iter__(self):
+        if self._start <= self._end:
+            for r in xrange(self._start, self._end):
+                yield r
+        else:
+            for r in xrange(self._start, self._end, -1):
+                yield r
+
+    def __contains__(self, x):
+        return (x <= self._start and x > self._end) or (x >= self._start and x<
+                self._end)
+
 # tell hggettext to extract docstrings from these functions:
 i18nfunctions = symbols.values()


More information about the Mercurial-devel mailing list