Patchwork [3,of,3] revset: do not partial-match operator and function names in optimize()

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 2, 2016, 2:58 p.m.
Message ID <1c24a66616699350c48a.1472828292@mimosa>
Download mbox | patch
Permalink /patch/16532/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 2, 2016, 2:58 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1470555368 -32400
#      Sun Aug 07 16:36:08 2016 +0900
# Node ID 1c24a66616699350c48aee283da06906ec9b4efa
# Parent  04d0742aa7ecb239a06ba46e9f8ebe0c52a86e9d
revset: do not partial-match operator and function names in optimize()

It was error-prone, and actually there was a typo, s/ancestorspec/ancestor/.
Pierre-Yves David - Sept. 6, 2016, 12:43 p.m.
On 09/02/2016 04:58 PM, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1470555368 -32400
> #      Sun Aug 07 16:36:08 2016 +0900
> # Node ID 1c24a66616699350c48aee283da06906ec9b4efa
> # Parent  04d0742aa7ecb239a06ba46e9f8ebe0c52a86e9d
> revset: do not partial-match operator and function names in optimize()
>
> It was error-prone, and actually there was a typo, s/ancestorspec/ancestor/.

I've pushed this series. Thanks.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2371,7 +2371,7 @@  def _optimize(x, small):
     elif op == 'negate':
         s = getstring(x[1], _("can't negate that"))
         return _optimize(('string', '-' + s), small)
-    elif op in 'string symbol':
+    elif op in ('string', 'symbol'):
         return smallbonus, x # single revisions are small
     elif op == 'and':
         wa, ta = _optimize(x[1], True)
@@ -2434,7 +2434,7 @@  def _optimize(x, small):
         return o[0], (op, o[1])
     elif op == 'group':
         return _optimize(x[1], small)
-    elif op in 'dagrange range parent ancestorspec':
+    elif op in ('dagrange', 'range', 'parent', 'ancestor'):
         wa, ta = _optimize(x[1], small)
         wb, tb = _optimize(x[2], small)
         return wa + wb, (op, ta, tb)
@@ -2447,18 +2447,18 @@  def _optimize(x, small):
     elif op == 'func':
         f = getsymbol(x[1])
         wa, ta = _optimize(x[2], small)
-        if f in ("author branch closed date desc file grep keyword "
-                 "outgoing user"):
+        if f in ('author', 'branch', 'closed', 'date', 'desc', 'file', 'grep',
+                 'keyword', 'outgoing', 'user'):
             w = 10 # slow
-        elif f in "modifies adds removes":
+        elif f in ('modifies', 'adds', 'removes'):
             w = 30 # slower
         elif f == "contains":
             w = 100 # very slow
         elif f == "ancestor":
             w = 1 * smallbonus
-        elif f in "reverse limit first _intlist":
+        elif f in ('reverse', 'limit', 'first', '_intlist'):
             w = 0
-        elif f in "sort":
+        elif f == "sort":
             w = 10 # assume most sorts look at changelog
         else:
             w = 1