revset: report a parse error if a revset is not parsed completely (
issue2654)
--- a/mercurial/commands.py Tue May 31 15:25:43 2011 -0500
+++ b/mercurial/commands.py Wed Mar 16 23:09:14 2011 +0100
@@ -1214,7 +1214,7 @@
def debugrevspec(ui, repo, expr):
'''parse and apply a revision specification'''
if ui.verbose:
- tree = revset.parse(expr)
+ tree = revset.parse(expr)[0]
ui.note(tree, "\n")
func = revset.match(expr)
for c in func(repo, range(len(repo))):
--- a/mercurial/parser.py Tue May 31 15:25:43 2011 -0500
+++ b/mercurial/parser.py Wed Mar 16 23:09:14 2011 +0100
@@ -78,7 +78,9 @@
'generate a parse tree from a message'
self._iter = self._tokenizer(message)
self._advance()
- return self._parse()
+ res = self._parse()
+ token, value, pos = self.current
+ return res, pos
def eval(self, tree):
'recursively evaluate a parse tree using node methods'
if not isinstance(tree, tuple):
--- a/mercurial/revset.py Tue May 31 15:25:43 2011 -0500
+++ b/mercurial/revset.py Wed Mar 16 23:09:14 2011 +0100
@@ -810,7 +810,9 @@
def match(spec):
if not spec:
raise error.ParseError(_("empty query"))
- tree = parse(spec)
+ tree, pos = parse(spec)
+ if (pos != len(spec)):
+ raise error.ParseError("invalid token", pos)
weight, tree = optimize(tree, True)
def mfunc(repo, subset):
return getset(repo, subset, tree)
--- a/mercurial/templater.py Tue May 31 15:25:43 2011 -0500
+++ b/mercurial/templater.py Wed Mar 16 23:09:14 2011 +0100
@@ -69,7 +69,6 @@
else:
raise error.ParseError(_("syntax error"), pos)
pos += 1
- data[2] = pos
yield ('end', None, pos)
def compiletemplate(tmpl, context):
@@ -91,8 +90,8 @@
parsed.append(("string", tmpl[pos:n]))
pd = [tmpl, n + 1, stop]
- parsed.append(p.parse(pd))
- pos = pd[2]
+ parseres, pos = p.parse(pd)
+ parsed.append(parseres)
return [compileexp(e, context) for e in parsed]
--- a/tests/test-revset.t Tue May 31 15:25:43 2011 -0500
+++ b/tests/test-revset.t Wed Mar 16 23:09:14 2011 +0100
@@ -356,3 +356,10 @@
9
$ log 'ancestors(8) and (heads(branch("-a-b-c-")) or heads(branch(é)))'
4
+
+issue2654: report a parse error if the revset was not completely parsed
+
+ $ log '1 OR 2'
+ hg: parse error at 2: invalid token
+ [255]
+