[PATCH 1 of 2 STABLE] addset: fix `first` and `last` on sorted addset (issue4426)

Pierre-Yves David pierre-yves.david at ens-lyon.org
Sat Nov 1 23:24:36 UTC 2014


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at fb.com>
# Date 1414882710 0
#      Sat Nov 01 22:58:30 2014 +0000
# Branch stable
# Node ID 03d8d72e9155209332e969a64b1ee0b3153478a3
# Parent  8b4a8a9176e2f596a0c90bd8366c4584e61d9832
addset: fix `first` and `last` on sorted addset (issue4426)

The lazy sorting were not enforced on addset. This was made visible through MQ.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2640,18 +2640,19 @@ class addset(abstractsmartset):
             self._list.reverse()
         else:
             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
 
     Wrapper structure for generators that provides lazy membership and can
diff --git a/tests/test-mq.t b/tests/test-mq.t
--- a/tests/test-mq.t
+++ b/tests/test-mq.t
@@ -1579,5 +1579,21 @@ Test that secret mq patch does not break
   $ QUERY_STRING='style=raw'
   $ python hgweb.cgi | grep '^tip'
   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 ..


More information about the Mercurial-devel mailing list