# HG changeset patch # User Lucas Moscovicz # Date 1391791458 28800 # Node ID 379e89e4b0790c19b225981bdd05b3bde149ccba # Parent cdecbc5ab5044595ca2d820a1b4933b5ec77c248 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. diff -r cdecbc5ab504 -r 379e89e4b079 mercurial/revset.py --- 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)