[PATCH 1 of 3] revset: added order methods to lazyset classes

Lucas Moscovicz lmoscovicz at fb.com
Fri Feb 28 17:27:49 CST 2014


# HG changeset patch
# User Lucas Moscovicz <lmoscovicz at fb.com>
# Date 1391791458 28800
#      Fri Feb 07 08:44:18 2014 -0800
# Node ID e43e2378c978d1bc53966e32c068fda061748904
# Parent  d9c1f97dac5f752a9def8f03bcb6604b8ee05c39
revset: added order methods to lazyset classes

This will allow revsets to ask for an ordered set when possible to be able to
work lazily with it.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2124,6 +2124,12 @@
         super(baseset, self).__init__(data)
         self._set = None
 
+    def ascending(self):
+        self.sort()
+
+    def descending(self):
+        self.sort(reverse=True)
+
     def set(self):
         if not self._set:
             self._set = set(self)
@@ -2159,6 +2165,12 @@
         self._condition = condition
         self._cache = {}
 
+    def ascending(self):
+        self._subset.sort()
+
+    def descending(self):
+        self._subset.sort(reverse=True)
+
     def __contains__(self, x):
         c = self._cache
         if x not in c:
@@ -2221,6 +2233,14 @@
     def filter(self, l):
         return orderedlazyset(self, l, ascending=self._ascending)
 
+    def ascending(self):
+        if not self._ascending:
+            self.reverse()
+
+    def descending(self):
+        if self._ascending:
+            self.reverse()
+
     def __and__(self, x):
         return orderedlazyset(self, lambda r: r in x,
                 ascending=self._ascending)
@@ -2229,6 +2249,10 @@
         return orderedlazyset(self, lambda r: r not in x,
                 ascending=self._ascending)
 
+    def reverse(self):
+        self._subset.reverse()
+        self._ascending = not self._ascending
+
 class generatorset(object):
     """Wrapper structure for generators that provides lazy membership and can
     be iterated more than once.
@@ -2296,6 +2320,14 @@
             self._end = len(repo)
         self._hiddenrevs = repo.changelog.filteredrevs
 
+    def ascending(self):
+        if self._start > self._end:
+            self.reverse()
+
+    def descending(self):
+        if self._start < self._end:
+            self.reverse()
+
     def _contained(self, rev):
         return (rev <= self._start and rev > self._end) or (rev >= self._start
                 and rev < self._end)


More information about the Mercurial-devel mailing list