Mercurial > hg
changeset 20657:379e89e4b079
revset: added order methods to lazyset classes
This will allow revsets to ask for an ordered set when possible to be able to
work lazily with it.
author | Lucas Moscovicz <lmoscovicz@fb.com> |
---|---|
date | Fri, 07 Feb 2014 08:44:18 -0800 |
parents | cdecbc5ab504 |
children | d7e96dd8e995 |
files | mercurial/revset.py |
diffstat | 1 files changed, 32 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/revset.py Thu Mar 06 12:37:28 2014 +0100 +++ b/mercurial/revset.py Fri Feb 07 08:44:18 2014 -0800 @@ -2146,6 +2146,12 @@ super(baseset, self).__init__(data) self._set = None + def ascending(self): + self.sort() + + def descending(self): + self.sort(reverse=True) + def set(self): if not self._set: self._set = set(self) @@ -2181,6 +2187,12 @@ self._condition = condition self._cache = {} + def ascending(self): + self._subset.sort() + + def descending(self): + self._subset.sort(reverse=True) + def __contains__(self, x): c = self._cache if x not in c: @@ -2249,6 +2261,14 @@ def filter(self, l): return orderedlazyset(self, l, ascending=self._ascending) + def ascending(self): + if not self._ascending: + self.reverse() + + def descending(self): + if self._ascending: + self.reverse() + def __and__(self, x): return orderedlazyset(self, lambda r: r in x, ascending=self._ascending) @@ -2257,6 +2277,10 @@ return orderedlazyset(self, lambda r: r not in x, ascending=self._ascending) + def reverse(self): + self._subset.reverse() + self._ascending = not self._ascending + class generatorset(object): """Wrapper structure for generators that provides lazy membership and can be iterated more than once. @@ -2342,6 +2366,14 @@ self._end = len(repo) self._hiddenrevs = repo.changelog.filteredrevs + def ascending(self): + if self._start > self._end: + self.reverse() + + def descending(self): + if self._start < self._end: + self.reverse() + def _contained(self, rev): return (rev <= self._start and rev > self._end) or (rev >= self._start and rev < self._end)