revset: fix order of last() n members where n > 1 (BC)
authorYuya Nishihara <yuya@tcha.org>
Sat, 10 Jun 2017 18:04:56 +0900
changeset 32798 573b792872c1
parent 32797 bcca357bb792
child 32799 b36ec65ea583
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."
mercurial/revset.py
tests/test-revset.t
--- 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")'