revset: fix keyword arguments to go through optimization process stable
authorYuya Nishihara <yuya@tcha.org>
Sun, 07 Aug 2016 14:58:49 +0900
branchstable
changeset 29766 5004ef47f437
parent 29717 a12d13eac513
child 29780 531e85eec23c
child 29847 9a9629b9416c
revset: fix keyword arguments to go through optimization process Before, a keyvalue node was processed by the last catch-all condition of _optimize(). Therefore, topo.firstbranch=expr would bypass tree rewriting and would crash if an expr wasn't trivial.
mercurial/revset.py
tests/test-revset.t
--- a/mercurial/revset.py	Mon Aug 08 16:47:42 2016 +0200
+++ b/mercurial/revset.py	Sun Aug 07 14:58:49 2016 +0900
@@ -2423,6 +2423,9 @@
     elif op == 'list':
         ws, ts = zip(*(_optimize(y, small) for y in x[1:]))
         return sum(ws), (op,) + ts
+    elif op == 'keyvalue':
+        w, t = _optimize(x[2], small)
+        return w, (op, x[1], t)
     elif op == 'func':
         f = getsymbol(x[1])
         wa, ta = _optimize(x[2], small)
--- a/tests/test-revset.t	Mon Aug 08 16:47:42 2016 +0200
+++ b/tests/test-revset.t	Sun Aug 07 14:58:49 2016 +0900
@@ -470,6 +470,25 @@
   hg: parse error: can't use a key-value pair in this context
   [255]
 
+ right-hand side should be optimized recursively
+
+  $ try --optimize 'foo=(not public())'
+  (keyvalue
+    ('symbol', 'foo')
+    (group
+      (not
+        (func
+          ('symbol', 'public')
+          None))))
+  * optimized:
+  (keyvalue
+    ('symbol', 'foo')
+    (func
+      ('symbol', '_notpublic')
+      None))
+  hg: parse error: can't use a key-value pair in this context
+  [255]
+
 Test that symbols only get parsed as functions if there's an opening
 parenthesis.
 
@@ -1649,6 +1668,11 @@
   hg: parse error: topo.firstbranch can only be used when using the topo sort key
   [255]
 
+topo.firstbranch should accept any kind of expressions:
+
+  $ hg log -r 'sort(0, topo, topo.firstbranch=(book1))'
+  0 b12  m111 u112 111 10800
+
   $ cd ..
   $ cd repo