changeset 22725:88e5483bfb20

lazyset: add order awareness to the class Just a bit of extra code makes the lazyset aware of order. This renders orderedlazyset useless. At some point, the `subset` will become responsible for this ordering logic. But we are not there yet because the various objects used as subsets are not good enough.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Thu, 02 Oct 2014 19:14:03 -0500
parents abdb46cf3b38
children 169aa5e74b52
files mercurial/revset.py
diffstat 1 files changed, 15 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Thu Oct 02 19:03:14 2014 -0500
+++ b/mercurial/revset.py	Thu Oct 02 19:14:03 2014 -0500
@@ -2409,7 +2409,7 @@
     the subset and contains a function which tests for membership in the
     revset
     """
-    def __init__(self, subset, condition=lambda x: True):
+    def __init__(self, subset, condition=lambda x: True, ascending=None):
         """
         condition: a function that decide whether a revision in the subset
                    belongs to the revset or not.
@@ -2417,6 +2417,9 @@
         self._subset = subset
         self._condition = condition
         self._cache = {}
+        if ascending is not None:
+            ascending = bool(ascending)
+        self._ascending = ascending
 
     def __contains__(self, x):
         c = self._cache
@@ -2473,21 +2476,27 @@
         return l[x]
 
     def sort(self, reverse=False):
-        if not util.safehasattr(self._subset, 'sort'):
-            self._subset = baseset(self._subset)
-        self._subset.sort(reverse=reverse)
+        if self._ascending is None:
+            if not util.safehasattr(self._subset, 'sort'):
+                self._subset = baseset(self._subset)
+            self._subset.sort(reverse=reverse)
+            self._ascending = not reverse
+        elif bool(reverse) == self._ascending:
+            self.reverse()
 
     def reverse(self):
         self._subset.reverse()
+        if self._ascending is not None:
+            self._ascending = not self._ascending
 
     def set(self):
         return set([r for r in self])
 
     def isascending(self):
-        return False
+        return self._ascending is not None and self._ascending
 
     def isdescending(self):
-        return False
+        return self._ascending is not None and not self._ascending
 
     def filter(self, l):
         return lazyset(self, l)