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

Pierre-Yves David pierre-yves.david at ens-lyon.org
Fri Sep 19 19:07:36 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 5aec2be794fbd94adc4f624c57cdd2fc9907e6e3
# Parent  9daf8851618b46b112314848bd639dadf6ca7381
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