addset: fix `first` and `last` on sorted addset (issue4426) stable
authorPierre-Yves David <pierre-yves.david@fb.com>
Sat, 01 Nov 2014 22:58:30 +0000
branchstable
changeset 23127 7361d8244efb
parent 23126 8b4a8a9176e2
child 23128 b6f7cf47f5d1
addset: fix `first` and `last` on sorted addset (issue4426) The lazy sorting were not enforced on addset. This was made visible through MQ.
mercurial/revset.py
tests/test-mq.t
--- a/mercurial/revset.py	Sat Nov 01 17:30:57 2014 -0500
+++ b/mercurial/revset.py	Sat Nov 01 22:58:30 2014 +0000
@@ -2642,14 +2642,15 @@
             self._ascending = not self._ascending
 
     def first(self):
-        if self:
-            return self._list.first()
+        for x in self:
+            return x
         return None
 
     def last(self):
-        if self:
-            return self._list.last()
-        return None
+        self.reverse()
+        val = self.first()
+        self.reverse()
+        return val
 
 class generatorset(abstractsmartset):
     """Wrap a generator for lazy iteration
--- a/tests/test-mq.t	Sat Nov 01 17:30:57 2014 -0500
+++ b/tests/test-mq.t	Sat Nov 01 22:58:30 2014 +0000
@@ -1581,3 +1581,19 @@
   tip	[0-9a-f]{40} (re)
 
   $ cd ..
+
+Test interraction with revset (issue4426)
+
+  $ hg init issue4426
+  $ cd issue4426
+
+  $ echo a > a
+  $ hg ci -Am a
+  adding a
+  $ echo a >> a
+  $ hg ci -m a
+  $ echo a >> a
+  $ hg ci -m a
+  $ hg qimport -r 0::
+
+  $ cd ..