changeset 20703:e07b1fd30805

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.
author Lucas Moscovicz <lmoscovicz@fb.com>
date Mon, 24 Feb 2014 16:36:17 -0800
parents 77ab0abb08a0
children 623ed0ed793e
files mercurial/revset.py
diffstat 1 files changed, 11 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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