Patchwork [STABLE] revset: map postfix '%' to only() to optimize operand recursively (issue4670)

login
register
mail settings
Submitter Yuya Nishihara
Date May 15, 2015, 2:19 p.m.
Message ID <8b99e9a8db05d77937a9.1431699559@mimosa>
Download mbox | patch
Permalink /patch/9098/
State Accepted
Headers show

Comments

Yuya Nishihara - May 15, 2015, 2:19 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1431696751 -32400
#      Fri May 15 22:32:31 2015 +0900
# Branch stable
# Node ID 8b99e9a8db05d77937a9905cc77e946171159acc
# Parent  bd98d073a34fcf9651a77a9265878db1f7c88044
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)'.
Matt Mackall - May 15, 2015, 4:07 p.m.
On Fri, 2015-05-15 at 23:19 +0900, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1431696751 -32400
> #      Fri May 15 22:32:31 2015 +0900
> # Branch stable
> # Node ID 8b99e9a8db05d77937a9905cc77e946171159acc
> # Parent  bd98d073a34fcf9651a77a9265878db1f7c88044
> revset: map postfix '%' to only() to optimize operand recursively (issue4670)

Queued for stable, thanks.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2098,7 +2098,6 @@  methods = {
     "parent": parentspec,
     "parentpost": p1,
     "only": only,
-    "onlypost": only,
 }
 
 def optimize(x, small):
@@ -2115,6 +2114,8 @@  def optimize(x, small):
     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':
diff --git a/tests/test-revset.t b/tests/test-revset.t
--- a/tests/test-revset.t
+++ b/tests/test-revset.t
@@ -533,6 +533,29 @@  Test '%' operator
   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'