Mercurial > public > mercurial-scm > hg
comparison mercurial/revset.py @ 22509:fbae659543cf
revset: turn spanset into a factory function
We rename the `spanset` class to `_spanset`. `spanset` is now a function that
builds 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 makes it easier to ensure we use the new
class whenever possible and focus on the benefits of this class.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Thu, 18 Sep 2014 13:04:02 -0700 |
parents | 2434c68d82a8 |
children | 911f5a6579d1 |
comparison
equal
deleted
inserted
replaced
22508:2434c68d82a8 | 22509:fbae659543cf |
---|---|
2730 break | 2730 break |
2731 | 2731 |
2732 self._cache[x] = False | 2732 self._cache[x] = False |
2733 return False | 2733 return False |
2734 | 2734 |
2735 class spanset(_orderedsetmixin): | 2735 def spanset(repo, start=None, end=None): |
2736 """factory function to dispatch between fullreposet and actual spanset | |
2737 | |
2738 Feel free to update all spanset call sites and kill this function at some | |
2739 point. | |
2740 """ | |
2741 if start is None and end is None: | |
2742 return fullreposet(repo) | |
2743 return _spanset(repo, start, end) | |
2744 | |
2745 | |
2746 class _spanset(_orderedsetmixin): | |
2736 """Duck type for baseset class which represents a range of revisions and | 2747 """Duck type for baseset class which represents a range of revisions and |
2737 can work lazily and without having all the range in memory | 2748 can work lazily and without having all the range in memory |
2738 | 2749 |
2739 Note that spanset(x, y) behave almost like xrange(x, y) except for two | 2750 Note that spanset(x, y) behave almost like xrange(x, y) except for two |
2740 notable points: | 2751 notable points: |
2849 return self._start >= self._end | 2860 return self._start >= self._end |
2850 | 2861 |
2851 def filter(self, l): | 2862 def filter(self, l): |
2852 return orderedlazyset(self, l, ascending=self.isascending()) | 2863 return orderedlazyset(self, l, ascending=self.isascending()) |
2853 | 2864 |
2854 class fullreposet(spanset): | 2865 class fullreposet(_spanset): |
2855 """a set containing all revisions in the repo | 2866 """a set containing all revisions in the repo |
2856 | 2867 |
2857 This class exists to host special optimisation. | 2868 This class exists to host special optimisation. |
2858 """ | 2869 """ |
2859 | 2870 |