[PATCH 7 of 7 V4] revset: optimize out sort() according to ordering policy (BC)

Yuya Nishihara yuya at tcha.org
Thu Jun 23 11:59:59 EDT 2016


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1462250172 -32400
#      Tue May 03 13:36:12 2016 +0900
# Node ID ed50041d829ef9adcd848d6e26d730dd558c74ee
# Parent  b6a2aa2e7f62d6c4c2351112556ab92b2be7a3ac
revset: optimize out sort() according to ordering policy (BC)

See the previous patch of reverse() for why. Unlike reverse(), we validate
the arguments by _getsortargs().

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2505,6 +2505,8 @@ def _optimize(x, small, order):
         wa, ta = _optimize(x[2], small, d)
         if f == 'reverse' and order != defineorder:
             return wa, ta
+        if f == 'sort' and order != defineorder:
+            return wa, _getsortargs(ta)[0]
         if f in ("author branch closed date desc file grep keyword "
                  "outgoing user"):
             w = 10 # slow
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -1367,20 +1367,24 @@ ordering defined by it.
       ('symbol', '2')
       ('string', 'define'))
     (func
-      ('symbol', 'sort')
-      (list
-        (func
-          ('symbol', 'all')
-          None)
-        ('string', '-rev'))))
+      ('symbol', 'all')
+      None))
   * set:
   <filteredset
-    <spanset- 0:2>,
+    <spanset+ 0:2>,
     <spanset+ 0:9>>
+  0
+  1
   2
-  1
-  0
- BROKEN: should be '0 1 2'
+
+ invalid argument passed to sort() to be optimized out:
+
+  $ log '0:2 & sort()'
+  hg: parse error: sort requires one or two arguments
+  [255]
+  $ log '0:2 & sort(all(), -invalid)'
+  hg: parse error: unknown sort key '-invalid'
+  [255]
 
  for 'A & f(B)', 'B' should not be affected by the order of 'A':
 


More information about the Mercurial-devel mailing list