Mercurial > hg
comparison mercurial/dispatch.py @ 28515:491eabd0df79
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.
author | Jun Wu <quark@fb.com> |
---|---|
date | Mon, 14 Mar 2016 12:32:09 +0000 |
parents | 4eb5496c2bd4 |
children | 84cc72c5771e |
comparison
equal
deleted
inserted
replaced
28514:0747ef2c4ab2 | 28515:491eabd0df79 |
---|---|
79 if (inst.args[0][0] == ' '): | 79 if (inst.args[0][0] == ' '): |
80 write(_("unexpected leading whitespace\n")) | 80 write(_("unexpected leading whitespace\n")) |
81 else: | 81 else: |
82 write(_("hg: parse error: %s\n") % inst.args[0]) | 82 write(_("hg: parse error: %s\n") % inst.args[0]) |
83 _reportsimilar(write, similar) | 83 _reportsimilar(write, similar) |
84 if inst.hint: | |
85 write(_("(%s)\n") % inst.hint) | |
84 | 86 |
85 def dispatch(req): | 87 def dispatch(req): |
86 "run the command specified in req.args" | 88 "run the command specified in req.args" |
87 if req.ferr: | 89 if req.ferr: |
88 ferr = req.ferr | 90 ferr = req.ferr |
109 if inst.hint: | 111 if inst.hint: |
110 ferr.write(_("(%s)\n") % inst.hint) | 112 ferr.write(_("(%s)\n") % inst.hint) |
111 return -1 | 113 return -1 |
112 except error.ParseError as inst: | 114 except error.ParseError as inst: |
113 _formatparse(ferr.write, inst) | 115 _formatparse(ferr.write, inst) |
114 if inst.hint: | |
115 ferr.write(_("(%s)\n") % inst.hint) | |
116 return -1 | 116 return -1 |
117 | 117 |
118 msg = ' '.join(' ' in a and repr(a) or a for a in req.args) | 118 msg = ' '.join(' ' in a and repr(a) or a for a in req.args) |
119 starttime = time.time() | 119 starttime = time.time() |
120 ret = None | 120 ret = None |
206 except error.AmbiguousCommand as inst: | 206 except error.AmbiguousCommand as inst: |
207 ui.warn(_("hg: command '%s' is ambiguous:\n %s\n") % | 207 ui.warn(_("hg: command '%s' is ambiguous:\n %s\n") % |
208 (inst.args[0], " ".join(inst.args[1]))) | 208 (inst.args[0], " ".join(inst.args[1]))) |
209 except error.ParseError as inst: | 209 except error.ParseError as inst: |
210 _formatparse(ui.warn, inst) | 210 _formatparse(ui.warn, inst) |
211 if inst.hint: | |
212 ui.warn(_("(%s)\n") % inst.hint) | |
213 return -1 | 211 return -1 |
214 except error.LockHeld as inst: | 212 except error.LockHeld as inst: |
215 if inst.errno == errno.ETIMEDOUT: | 213 if inst.errno == errno.ETIMEDOUT: |
216 reason = _('timed out waiting for lock held by %s') % inst.locker | 214 reason = _('timed out waiting for lock held by %s') % inst.locker |
217 else: | 215 else: |