Patchwork [2,of,5] fileset: move validation of incomplete parsing to parse() function

login
register
mail settings
Submitter Yuya Nishihara
Date May 22, 2015, 2:11 p.m.
Message ID <82c474fa3f0e744f8fe6.1432303905@mimosa>
Download mbox | patch
Permalink /patch/9236/
State Accepted
Headers show

Comments

Yuya Nishihara - May 22, 2015, 2:11 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1430045442 -32400
#      Sun Apr 26 19:50:42 2015 +0900
# Node ID 82c474fa3f0e744f8fe63a00c9657c6998886cd5
# Parent  62ad2453a1ff2652cc8be95db091eadbb5aed6de
fileset: move validation of incomplete parsing to parse() function

fileset.parse() should be responsible for all parsing errors as well.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2164,7 +2164,7 @@  def debugfileset(ui, repo, expr, **opts)
     '''parse and apply a fileset specification'''
     ctx = scmutil.revsingle(repo, opts.get('rev'), None)
     if ui.verbose:
-        tree = fileset.parse(expr)[0]
+        tree = fileset.parse(expr)
         ui.note(tree, "\n")
 
     for f in ctx.getfileset(expr):
diff --git a/mercurial/fileset.py b/mercurial/fileset.py
--- a/mercurial/fileset.py
+++ b/mercurial/fileset.py
@@ -81,7 +81,10 @@  def tokenize(program):
 
 def parse(expr):
     p = parser.parser(tokenize, elements)
-    return p.parse(expr)
+    tree, pos = p.parse(expr)
+    if pos != len(expr):
+        raise error.ParseError(_("invalid token"), pos)
+    return tree
 
 def getstring(x, err):
     if x and (x[0] == 'string' or x[0] == 'symbol'):
@@ -491,9 +494,7 @@  def _intree(funcs, tree):
 ]
 
 def getfileset(ctx, expr):
-    tree, pos = parse(expr)
-    if (pos != len(expr)):
-        raise error.ParseError(_("invalid token"), pos)
+    tree = parse(expr)
 
     # do we need status info?
     if (_intree(['modified', 'added', 'removed', 'deleted',