[PATCH 3 of 4 V2] revset: turn spanset into a factory function

Pierre-Yves David pierre-yves.david at ens-lyon.org
Tue Sep 23 14:28:28 CDT 2014


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1411070642 25200
#      Thu Sep 18 13:04:02 2014 -0700
# Node ID bfa28d90f22b612283e211a8472b8a46e48f1eea
# Parent  52b6a97deaae46cd25bd342c35c74edf7a577c3d
revset: turn spanset into a factory function

We rename the `spanset` class to `_spanset`. `spanset` is now a function that
build either a `fullreposet` or a `_spanset` according to the argument passed.

At some point we may force people to explicitly use the `fullreposet`
constructor but the current approach make is easier to ensure we use the new
class whenever possible and focus on the benefit of this class.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2726,11 +2726,22 @@ class _descgeneratorset(_generatorset):
                 break
 
         self._cache[x] = False
         return False
 
-class spanset(_orderedsetmixin):
+def spanset(repo, start=None, end=None):
+    """factory function to dispatch between fullreposet and actual spanset
+
+    Feel will to update all spanset call site and kill this function at some
+    point.
+    """
+    if start is None and end is None:
+        return fullreposet(repo)
+    return _spanset(repo, start, end)
+
+
+class _spanset(_orderedsetmixin):
     """Duck type for baseset class which represents a range of revisions and
     can work lazily and without having all the range in memory
 
     Note that spanset(x, y) behave almost like xrange(x, y) except for two
     notable points:
@@ -2845,11 +2856,11 @@ class spanset(_orderedsetmixin):
         return self._start >= self._end
 
     def filter(self, l):
         return orderedlazyset(self, l, ascending=self.isascending())
 
-class fullreposet(spanset):
+class fullreposet(_spanset):
     """a set containing all revisions in the repo
 
     This class exists to host special optimisation.
     """
 


More information about the Mercurial-devel mailing list