# HG changeset patch # User Yuya Nishihara # Date 1432433234 -32400 # Node ID 9ddb18ae342eb45bcbb48f6610798586e0b9faf1 # Parent e962c70c0aadf1dcfbc5435e370da57eabca1987 smartset: extract spanset factory to make it constructed without a repo This renames the spanset class to _spanset, and moves its __init__ to new spanset() function. spanset() is now a factory function. This allows us to construct a spanset without keeping a repo instance. diff -r e962c70c0aad -r 9ddb18ae342e mercurial/smartset.py --- a/mercurial/smartset.py Sun Jun 11 00:21:38 2017 +0900 +++ b/mercurial/smartset.py Sun May 24 11:07:14 2015 +0900 @@ -906,7 +906,22 @@ d = {False: '-', True: '+'}[self._ascending] return '<%s%s>' % (type(self).__name__, d) -class spanset(abstractsmartset): +def spanset(repo, start=0, end=None): + """Create a spanset that represents a range of repository revisions + + start: first revision included the set (default to 0) + end: first revision excluded (last+1) (default to len(repo)) + + Spanset will be descending if `end` < `start`. + """ + if end is None: + end = len(repo) + ascending = start <= end + if not ascending: + start, end = end + 1, start + 1 + return _spanset(start, end, ascending, repo.changelog.filteredrevs) + +class _spanset(abstractsmartset): """Duck type for baseset class which represents a range of revisions and can work lazily and without having all the range in memory @@ -916,23 +931,11 @@ - revision filtered with this repoview will be skipped. """ - def __init__(self, repo, start=0, end=None): - """ - start: first revision included the set - (default to 0) - end: first revision excluded (last+1) - (default to len(repo) - - Spanset will be descending if `end` < `start`. - """ - if end is None: - end = len(repo) - self._ascending = start <= end - if not self._ascending: - start, end = end + 1, start +1 + def __init__(self, start, end, ascending, hiddenrevs): self._start = start self._end = end - self._hiddenrevs = repo.changelog.filteredrevs + self._ascending = ascending + self._hiddenrevs = hiddenrevs def sort(self, reverse=False): self._ascending = not reverse @@ -1020,10 +1023,10 @@ def __repr__(self): d = {False: '-', True: '+'}[self._ascending] - return '<%s%s %d:%d>' % (type(self).__name__, d, + return '<%s%s %d:%d>' % (type(self).__name__.lstrip('_'), d, self._start, self._end) -class fullreposet(spanset): +class fullreposet(_spanset): """a set containing all revisions in the repo This class exists to host special optimization and magic to handle virtual @@ -1031,7 +1034,8 @@ """ def __init__(self, repo): - super(fullreposet, self).__init__(repo) + super(fullreposet, self).__init__(0, len(repo), True, + repo.changelog.filteredrevs) def __and__(self, other): """As self contains the whole repo, all of the other set should also be