changeset 25094:8b99e9a8db05 stable

revset: map postfix '%' to only() to optimize operand recursively (issue4670) Instead of keeping 'onlypost' as a method, this patch rewrites it to 'only' function. This way, 'x%' always has the same weight as 'only(x)'.
author Yuya Nishihara <yuya@tcha.org>
date Fri, 15 May 2015 22:32:31 +0900
parents bd98d073a34f
children 91c2278c68a3
files mercurial/revset.py tests/test-revset.t
diffstat 2 files changed, 25 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revset.py	Sun May 10 10:57:24 2015 -0400
+++ b/mercurial/revset.py	Fri May 15 22:32:31 2015 +0900
@@ -2098,7 +2098,6 @@
     "parent": parentspec,
     "parentpost": p1,
     "only": only,
-    "onlypost": only,
 }
 
 def optimize(x, small):
@@ -2115,6 +2114,8 @@
     elif op == 'only':
         return optimize(('func', ('symbol', 'only'),
                          ('list', x[1], x[2])), small)
+    elif op == 'onlypost':
+        return optimize(('func', ('symbol', 'only'), x[1]), small)
     elif op == 'dagrangepre':
         return optimize(('func', ('symbol', 'ancestors'), x[1]), small)
     elif op == 'dagrangepost':
--- a/tests/test-revset.t	Sun May 10 10:57:24 2015 -0400
+++ b/tests/test-revset.t	Fri May 15 22:32:31 2015 +0900
@@ -533,6 +533,29 @@
   8
   9
 
+Test opreand of '%' is optimized recursively (issue4670)
+
+  $ try --optimize '8:9-8%'
+  (onlypost
+    (minus
+      (range
+        ('symbol', '8')
+        ('symbol', '9'))
+      ('symbol', '8')))
+  * optimized:
+  (func
+    ('symbol', 'only')
+    (and
+      (range
+        ('symbol', '8')
+        ('symbol', '9'))
+      (not
+        ('symbol', '8'))))
+  * set:
+  <baseset+ [8, 9]>
+  8
+  9
+
 Test the order of operations
 
   $ log '7 + 9%5 + 2'