[PATCH] revset: rework 'filteredset.last'

Pierre-Yves David pierre-yves.david at ens-lyon.org
Mon Jun 22 16:57:30 CDT 2015


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1435006081 25200
#      Mon Jun 22 13:48:01 2015 -0700
# Node ID 5436ea241ec1c12294d7868de6c679d10d333060
# Parent  7fdd1782fc4ee9da87d8af13e806dc9055db2c38
revset: rework 'filteredset.last'

As 'isascending' and 'isdescending' are method, not attribute. This led 'last()'
to misbehave on some non-ascending filtered set.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -3022,20 +3022,22 @@ class filteredset(abstractsmartset):
             return x
         return None
 
     def last(self):
         it = None
-        if self._subset.isascending:
+        if self.isascending():
             it = self.fastdesc
-        elif self._subset.isdescending:
-            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
+        else:
+            for x in self:
+                pass
             return x
-        return None
+        return None #empty case
 
     def __repr__(self):
         return '<%s %r>' % (type(self).__name__, self._subset)
 
 # this function will be removed, or merged to addset or orset, when


More information about the Mercurial-devel mailing list