changeset 22800:29a8c20e14a8

generatorset: explicitly track iteration order The expected iteration order may be different than the fast iteration order (eg: ancestors(42) is expected to be iterated upward but is fast/lazy to compute downward. So we explicitly track the iteration order and enforce it if the manual iteration is requested. Default expected iteration order of a generator set is ascending because I'm not aware of any descending revset that need a generatorset. The first to find such descending revset will have the pleasure to make this configurable.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Fri, 03 Oct 2014 21:11:56 -0700
parents bafa371d7af3
children 6af9e9b6af39
files mercurial/revset.py
diffstat 1 files changed, 16 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Fri Oct 03 20:23:02 2014 -0700
+++ b/mercurial/revset.py	Fri Oct 03 21:11:56 2014 -0700
@@ -2623,6 +2623,7 @@
         self._cache = {}
         self._genlist = []
         self._finished = False
+        self._ascending = True
         if iterasc is not None:
             if iterasc:
                 self.fastasc = self._iterator
@@ -2679,7 +2680,17 @@
         return False
 
     def __iter__(self):
-        return self._iterator()
+        if self._ascending:
+            it = self.fastasc
+        else:
+            it = self.fastdesc
+        if it is not None:
+            return it()
+        # we need to consume the iterator
+        for x in self._consumegen():
+            pass
+        # recall the same code
+        return iter(self)
 
     def _iterator(self):
         if self._finished:
@@ -2723,10 +2734,10 @@
         return self
 
     def sort(self, reverse=False):
-        if not self._finished:
-            for i in self:
-                continue
-        self._genlist.sort(reverse=reverse)
+        self._ascending = not reverse
+
+    def reverse(self):
+        self._ascending = not self._ascending
 
 def spanset(repo, start=None, end=None):
     """factory function to dispatch between fullreposet and actual spanset