Patchwork [1,of,5] revset: 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 <62ad2453a1ff2652cc8b.1432303904@mimosa>
Download mbox | patch
Permalink /patch/9235/
State Accepted
Headers show

Comments

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

revset.parse() should be responsible for all parsing errors. Perhaps it wasn't
because 'revset.parse' was not a real function when the validation code was
added at ffcb7e4d719f.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2918,7 +2918,7 @@  def debugrevspec(ui, repo, expr, **opts)
     expansion.
     """
     if ui.verbose:
-        tree = revset.parse(expr)[0]
+        tree = revset.parse(expr)
         ui.note(revset.prettyformat(tree), "\n")
         newtree = revset.findaliases(ui, tree)
         if newtree != tree:
diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -223,7 +223,7 @@  def _search(web, req, tmpl):
 
         revdef = 'reverse(%s)' % query
         try:
-            tree, pos = revset.parse(revdef)
+            tree = revset.parse(revdef)
         except ParseError:
             # can't parse to a revset tree
             return MODE_KEYWORD, query
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -2509,7 +2509,10 @@  def foldconcat(tree):
 
 def parse(spec, lookup=None):
     p = parser.parser(tokenize, elements)
-    return p.parse(spec, lookup=lookup)
+    tree, pos = p.parse(spec, lookup=lookup)
+    if pos != len(spec):
+        raise error.ParseError(_("invalid token"), pos)
+    return tree
 
 def posttreebuilthook(tree, repo):
     # hook for extensions to execute code on the optimized tree
@@ -2521,9 +2524,7 @@  def match(ui, spec, repo=None):
     lookup = None
     if repo:
         lookup = repo.__contains__
-    tree, pos = parse(spec, lookup)
-    if (pos != len(spec)):
-        raise error.ParseError(_("invalid token"), pos)
+    tree = parse(spec, lookup)
     if ui:
         tree = findaliases(ui, tree, showwarning=ui.warn)
     tree = foldconcat(tree)
diff --git a/tests/test-glog.t b/tests/test-glog.t
--- a/tests/test-glog.t
+++ b/tests/test-glog.t
@@ -89,7 +89,7 @@  o  (0) root
   >         if opts.get('print_revset'):
   >             expr = cmdutil.getgraphlogrevs(repo, pats, opts)[1]
   >             if expr:
-  >                 tree = revset.parse(expr)[0]
+  >                 tree = revset.parse(expr)
   >             else:
   >                 tree = []
   >             ui.write('%r\n' % (opts.get('rev', []),))