[PATCH 6 of 6] revset: fix order of first/last members in compound expression (BC)

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


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1497091728 -32400
#      Sat Jun 10 19:48:48 2017 +0900
# Node ID 0fcda861cf6a78f36ffae19bbda0e8150d43ae22
# Parent  24b03ed1d589fac6ebbcd6eea00bf6f749a5cd72
revset: fix order of first/last members in compound expression (BC)

Suppose len(subset) >> len(ls) in common cases, 'subset & ls' should be
avoided whenever possible.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -884,11 +884,11 @@ def filelog(repo, subset, x):
 
     return subset & s
 
- at predicate('first(set, [n])', safe=True)
-def first(repo, subset, x):
+ at predicate('first(set, [n])', safe=True, takeorder=True)
+def first(repo, subset, x, order):
     """An alias for limit().
     """
-    return limit(repo, subset, x)
+    return limit(repo, subset, x, order)
 
 def _follow(repo, subset, x, name, followfirst=False):
     l = getargs(x, 0, 2, _("%s takes no arguments or a pattern "
@@ -1152,8 +1152,8 @@ def keyword(repo, subset, x):
 
     return subset.filter(matches, condrepr=('<keyword %r>', kw))
 
- at predicate('limit(set[, n[, offset]])', safe=True)
-def limit(repo, subset, x):
+ at predicate('limit(set[, n[, offset]])', safe=True, takeorder=True)
+def limit(repo, subset, x, order):
     """First n members of set, defaulting to 1, starting from offset.
     """
     args = getargsdict(x, 'limit', 'set n offset')
@@ -1181,10 +1181,12 @@ def limit(repo, subset, x):
             break
         result.append(y)
     ls = baseset(result, datarepr=('<limit n=%d, offset=%d, %r>', lim, ofs, os))
+    if order == followorder and lim > 1:
+        return subset & ls
     return ls & subset
 
- at predicate('last(set, [n])', safe=True)
-def last(repo, subset, x):
+ at predicate('last(set, [n])', safe=True, takeorder=True)
+def last(repo, subset, x, order):
     """Last n members of set, defaulting to 1.
     """
     # i18n: "last" is a keyword
@@ -1205,6 +1207,8 @@ def last(repo, subset, x):
             break
         result.append(y)
     ls = baseset(result, datarepr=('<last n=%d, %r>', lim, os))
+    if order == followorder and lim > 1:
+        return subset & ls
     ls.reverse()
     return ls & subset
 
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -1031,13 +1031,12 @@ Test order of first/last revisions
   $ hg debugrevspec -s '3: & first(4:0, 3)'
   * set:
   <filteredset
+    <spanset+ 3:9>,
     <baseset
       <limit n=3, offset=0,
-        <spanset- 0:4>>>,
-    <spanset+ 3:9>>
+        <spanset- 0:4>>>>
+  3
   4
-  3
-BROKEN: should be '3 4'
 
   $ hg debugrevspec -s 'last(4:0, 3) & :1'
   * set:
@@ -1052,13 +1051,12 @@ BROKEN: should be '3 4'
   $ hg debugrevspec -s ':1 & last(4:0, 3)'
   * set:
   <filteredset
+    <spanset+ 0:1>,
     <baseset
       <last n=3,
-        <spanset+ 0:4>>>,
-    <spanset+ 0:1>>
+        <spanset+ 0:4>>>>
+  0
   1
-  0
-BROKEN: should be '0 1'
 
 Test matching
 


More information about the Mercurial-devel mailing list