revset: rework 'filteredset.last'
authorPierre-Yves David <pierre-yves.david@fb.com>
Mon, 22 Jun 2015 13:48:01 -0700
changeset 25648 9b9877d2b229
parent 25647 46a96dd4d976
child 25649 e90e031b3016
revset: rework 'filteredset.last' 'isascending' and 'isdescending' are methods, not attributes. This led 'last()' to misbehave on some non-ascending filtered sets.
mercurial/revset.py
--- a/mercurial/revset.py	Mon Jun 22 10:19:12 2015 -0700
+++ b/mercurial/revset.py	Mon Jun 22 13:48:01 2015 -0700
@@ -3028,16 +3028,19 @@
 
     def last(self):
         it = None
-        if self._subset.isascending:
-            it = self.fastdesc
-        elif self._subset.isdescending:
+        if self.isascending():
             it = self.fastdesc
-        if it is None:
-            # slowly consume everything. This needs improvement
-            it = lambda: reversed(list(self))
-        for x in it():
+        elif self.isdescending():
+            it = self.fastasc
+        if it is not None:
+            for x in it():
+                return x
+            return None #empty case
+        else:
+            x = None
+            for x in self:
+                pass
             return x
-        return None
 
     def __repr__(self):
         return '<%s %r>' % (type(self).__name__, self._subset)