Mercurial > public > mercurial-scm > hg
comparison mercurial/dispatch.py @ 31493:7e9c7d1d65cb
dispatch: extract maybe-use-repr formatting to helper function
I think this makes the code much clearer. I had to think for a bit to
unpack the old-school `condition and if-true or if-false` dance, and
formatting argument lists here shouldn't be performance critical.
author | Augie Fackler <augie@google.com> |
---|---|
date | Sun, 19 Mar 2017 00:21:26 -0400 |
parents | 3c77414a0f9c |
children | faf75a701aca |
comparison
equal
deleted
inserted
replaced
31492:3c77414a0f9c | 31493:7e9c7d1d65cb |
---|---|
90 write(_("hg: parse error: %s\n") % inst.args[0]) | 90 write(_("hg: parse error: %s\n") % inst.args[0]) |
91 _reportsimilar(write, similar) | 91 _reportsimilar(write, similar) |
92 if inst.hint: | 92 if inst.hint: |
93 write(_("(%s)\n") % inst.hint) | 93 write(_("(%s)\n") % inst.hint) |
94 | 94 |
95 def _mayberepr(a): | |
96 if ' ' in a: | |
97 return repr(a) | |
98 return a | |
99 | |
95 def _formatargs(args): | 100 def _formatargs(args): |
96 return ' '.join(' ' in a and repr(a) or a for a in args) | 101 return ' '.join(_mayberepr(a) for a in args) |
97 | 102 |
98 def dispatch(req): | 103 def dispatch(req): |
99 "run the command specified in req.args" | 104 "run the command specified in req.args" |
100 if req.ferr: | 105 if req.ferr: |
101 ferr = req.ferr | 106 ferr = req.ferr |