[PATCH 3 of 6] revset: fix order of last() n members where n > 1 (BC)

Yuya Nishihara yuya at tcha.org
Sun Jun 11 01:36:13 EDT 2017


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1497085496 -32400
#      Sat Jun 10 18:04:56 2017 +0900
# Node ID 1d108aa3519ed6318b498171e0e52f9efabcb19f
# Parent  cddc126a257e5e8bf5bdd919012f36c05d6963dd
revset: fix order of last() n members where n > 1 (BC)

last() is implemented using a reversed iterator, so the result should be
reversed again.

I've marked this as BC since it's quite old bug seen in 3.0. The first bad
revision is 4849f574aa24 "revset: changed last implementation to use lazy
classes."

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -1202,7 +1202,8 @@ def last(repo, subset, x):
             break
         elif y in subset:
             result.append(y)
-    return baseset(result, datarepr=('<last n=%d, %r, %r>', lim, subset, os))
+    return baseset(result[::-1], datarepr=('<last n=%d, %r, %r>',
+                                           lim, subset, os))
 
 @predicate('max(set)', safe=True)
 def maxrev(repo, subset, x):
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -986,6 +986,9 @@ test ancestors
   $ log 'keyword(issue)'
   6
   $ log 'keyword("test a")'
+
+Test first (=limit) and last
+
   $ log 'limit(head(), 1)'
   0
   $ log 'limit(author("re:bob|test"), 3, 5)'
@@ -998,6 +1001,16 @@ test ancestors
   $ log 'limit(all(), 1, -1)'
   hg: parse error: negative offset
   [255]
+
+  $ log 'last(all(), 0)'
+  $ log 'last(all(), 1)'
+  9
+  $ log 'last(all(), 2)'
+  8
+  9
+
+Test matching
+
   $ log 'matching(6)'
   6
   $ log 'matching(6:7, "phase parents user date branch summary files description substate")'


More information about the Mercurial-devel mailing list