changeset 32798:573b792872c1

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."
author Yuya Nishihara <yuya@tcha.org>
date Sat, 10 Jun 2017 18:04:56 +0900
parents bcca357bb792
children b36ec65ea583
files mercurial/revset.py tests/test-revset.t
diffstat 2 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Sat Jun 10 20:14:23 2017 +0900
+++ b/mercurial/revset.py	Sat Jun 10 18:04:56 2017 +0900
@@ -1202,7 +1202,8 @@
             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):
--- a/tests/test-revset.t	Sat Jun 10 20:14:23 2017 +0900
+++ b/tests/test-revset.t	Sat Jun 10 18:04:56 2017 +0900
@@ -986,6 +986,9 @@
   $ 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 @@
   $ 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")'