mercurial/revset.py
changeset 20657 379e89e4b079
parent 20643 7fc371d2e5a3
child 20658 d7e96dd8e995
--- 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)