dispatch: extract common logic for handling ParseError
authorJun Wu <quark@fb.com>
Mon, 14 Mar 2016 12:32:09 +0000
changeset 28515 491eabd0df79
parent 28514 0747ef2c4ab2
child 28516 3bf2892f685f
dispatch: extract common logic for handling ParseError The way ParseError is handled at two different places in dispatch.py is the same. Move common logic into _formatparse.
mercurial/dispatch.py
--- a/mercurial/dispatch.py	Mon Mar 14 11:23:04 2016 +0000
+++ b/mercurial/dispatch.py	Mon Mar 14 12:32:09 2016 +0000
@@ -81,6 +81,8 @@
     else:
         write(_("hg: parse error: %s\n") % inst.args[0])
         _reportsimilar(write, similar)
+    if inst.hint:
+        write(_("(%s)\n") % inst.hint)
 
 def dispatch(req):
     "run the command specified in req.args"
@@ -111,8 +113,6 @@
         return -1
     except error.ParseError as inst:
         _formatparse(ferr.write, inst)
-        if inst.hint:
-            ferr.write(_("(%s)\n") % inst.hint)
         return -1
 
     msg = ' '.join(' ' in a and repr(a) or a for a in req.args)
@@ -208,8 +208,6 @@
                 (inst.args[0], " ".join(inst.args[1])))
     except error.ParseError as inst:
         _formatparse(ui.warn, inst)
-        if inst.hint:
-            ui.warn(_("(%s)\n") % inst.hint)
         return -1
     except error.LockHeld as inst:
         if inst.errno == errno.ETIMEDOUT: