Patchwork [4,of,6] fileset: flatten arguments list

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 2, 2018, 1:26 p.m.
Message ID <4391366a156f0a976460.1533216364@mimosa>
Download mbox | patch
Permalink /patch/33103/
State Accepted
Headers show

Comments

Yuya Nishihara - Aug. 2, 2018, 1:26 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1532153678 -32400
#      Sat Jul 21 15:14:38 2018 +0900
# Node ID 4391366a156f0a976460deccaa176217e50a3650
# Parent  75b53fecd632963175bc86d20fd8458774583211
fileset: flatten arguments list

Just prepares for flattening 'or' nodes. This change would have no impact on
performance.

Patch

diff --git a/mercurial/fileset.py b/mercurial/fileset.py
--- a/mercurial/fileset.py
+++ b/mercurial/fileset.py
@@ -103,7 +103,7 @@  def parse(expr):
     tree, pos = p.parse(tokenize(expr))
     if pos != len(expr):
         raise error.ParseError(_("invalid token"), pos)
-    return tree
+    return parser.simplifyinfixops(tree, {'list'})
 
 def getsymbol(x):
     if x and x[0] == 'symbol':
@@ -131,7 +131,7 @@  def getlist(x):
     if not x:
         return []
     if x[0] == 'list':
-        return getlist(x[1]) + [x[2]]
+        return list(x[1:])
     return [x]
 
 def getargs(x, min, max, err):
@@ -174,7 +174,7 @@  def minusmatch(mctx, x, y):
 def negatematch(mctx, x):
     raise error.ParseError(_("can't use negate operator in this context"))
 
-def listmatch(mctx, x, y):
+def listmatch(mctx, *xs):
     raise error.ParseError(_("can't use a list in this context"),
                            hint=_('see hg help "filesets.x or y"'))
 
diff --git a/tests/test-fileset.t b/tests/test-fileset.t
--- a/tests/test-fileset.t
+++ b/tests/test-fileset.t
@@ -111,6 +111,15 @@  Test invalid syntax
       None))
   hg: parse error: can't use negate operator in this context
   [255]
+  $ fileset -p parsed 'a, b, c'
+  * parsed:
+  (list
+    (symbol 'a')
+    (symbol 'b')
+    (symbol 'c'))
+  hg: parse error: can't use a list in this context
+  (see hg help "filesets.x or y")
+  [255]
 
   $ fileset '"path":.'
   hg: parse error: not a symbol