[PATCH] revsets: indicate source of ParseErrors is from revsets

timeless timeless at gmail.com
Fri Jun 18 07:20:32 CDT 2010


Using revsets, it's really annoying to get errors which just claim to
be 'parse error':

hg log -r 'file(5/f)'
hg: parse error at 6: syntax error
hg log -r 'ancestor(1::5) '
hg: parse error: ancestor wants two args

# HG changeset patch
# User timeless <timeless at gmail.com>
# Date 1276863509 -10800
# Node ID a1984c91375a27492516cfc4eca8b684144d2299
# Parent  91a51c8cc81407391143ca1a4899014c4df9c92c
revsets: indicate source of ParseErrors is from revsets

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -67,7 +67,10 @@ def _runcatch(ui, args):
         ui.warn(_("hg: command '%s' is ambiguous:\n    %s\n") %
                 (inst.args[0], " ".join(inst.args[1])))
     except error.ParseError, inst:
-        if len(inst.args) > 1:
+        if len(inst.args) > 2:
+            ui.warn(_("hg: parse error in %s at %s: %s\n") %
+                             (inst.args[2], inst.args[1], inst.args[0]))
+        elif len(inst.args) > 1:
             ui.warn(_("hg: parse error at %s: %s\n") %
                              (inst.args[1], inst.args[0]))
         else:
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -545,8 +545,27 @@ def optimize(x, small):
 parse = parser.parser(tokenize, elements).parse

 def match(spec):
-    tree = parse(spec)
-    weight, tree = optimize(tree, True)
+    class RevsetError(error.ParseError):
+        def __init__(self, *args):
+            message = None
+            count = len(args)
+            pargs = [x for x in args]
+            if (count > 1):
+                pargs[1] = 'char %s' % pargs[1]
+            else:
+                pargs.insert(1, 'unknown')
+            pargs.insert(2, 'revsets')
+            error.ParseError.__init__(self, *pargs)
+
     def mfunc(repo, subset):
-        return getset(repo, subset, tree)
-    return mfunc
+        try:
+            return getset(repo, subset, tree)
+        except error.ParseError, e:
+            raise RevsetError(*e.args)
+
+    try:
+        tree = parse(spec)
+        weight, tree = optimize(tree, True)
+        return mfunc
+    except error.ParseError, e:
+        raise RevsetError(*e.args)


More information about the Mercurial-devel mailing list