changeset 20724:e9a64b3f2925

revset: added sort method in addset We need this method to duck-type generatorset since this class is not going to be used outside revset.py and we don't need to duck-type baseset. This sort method will only do something when the addset is not already sorted or is not sorted in the way we want it to be.
author Lucas Moscovicz <lmoscovicz@fb.com>
date Tue, 11 Mar 2014 17:03:43 -0700
parents fb9852c46a42
children cf628b50afbb
files mercurial/revset.py
diffstat 1 files changed, 13 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Thu Mar 13 18:57:30 2014 -0700
+++ b/mercurial/revset.py	Tue Mar 11 17:03:43 2014 -0700
@@ -2409,6 +2409,19 @@
     def set(self):
         return self
 
+    def sort(self, reverse=False):
+        """Sort the added set
+
+        For this we use the cached list with all the generated values and if we
+        know they are ascending or descending we can sort them in a smart way.
+        """
+        if self._ascending is None:
+            self._list.sort(reverse=reverse)
+            self._ascending = not reverse
+        else:
+            if bool(self._ascending) == bool(reverse):
+                self.reverse()
+
     def reverse(self):
         self._list.reverse()
         if self._ascending is not None: