revset: added sort methods to generatorsets
authorLucas Moscovicz <lmoscovicz@fb.com>
Mon, 24 Feb 2014 16:36:17 -0800
changeset 20703 e07b1fd30805
parent 20696 77ab0abb08a0
child 20704 623ed0ed793e
revset: added sort methods to generatorsets Method needed to propagate sort calls amongst lazy structures. The generated list (stored in the object) is sorted. If the generated list did not contain all elements from the generator, we take care of that before sorting the list.
mercurial/revset.py
--- a/mercurial/revset.py	Thu Sep 19 15:38:42 2013 -0400
+++ b/mercurial/revset.py	Mon Feb 24 16:36:17 2014 -0800
@@ -2348,6 +2348,7 @@
         self._cache = {}
         self._genlist = baseset([])
         self._iterated = False
+        self._finished = False
 
     def __contains__(self, x):
         if x in self._cache:
@@ -2357,6 +2358,7 @@
             if l == x:
                 return True
 
+        self._finished = True
         self._cache[x] = False
         return False
 
@@ -2372,9 +2374,18 @@
             self._genlist.append(item)
             yield item
 
+        self._finished = True
+
     def set(self):
         return self
 
+    def sort(self, reverse=False):
+        # Basic implementation to be changed in future patches
+        if not self._finished:
+            for i in self:
+                continue
+        self._genlist.sort(reverse=reverse)
+
 class ascgeneratorset(generatorset):
     """ Same structure as generatorset but stops iterating after it goes past
     the value when asked for membership and the element is not contained