dispatch: extract maybe-use-repr formatting to helper function
authorAugie Fackler <augie@google.com>
Sun, 19 Mar 2017 00:21:26 -0400
changeset 31493 7e9c7d1d65cb
parent 31492 3c77414a0f9c
child 31494 faf75a701aca
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.
mercurial/dispatch.py
--- a/mercurial/dispatch.py	Sun Mar 19 00:18:53 2017 -0400
+++ b/mercurial/dispatch.py	Sun Mar 19 00:21:26 2017 -0400
@@ -92,8 +92,13 @@
     if inst.hint:
         write(_("(%s)\n") % inst.hint)
 
+def _mayberepr(a):
+    if ' ' in a:
+        return repr(a)
+    return a
+
 def _formatargs(args):
-    return ' '.join(' ' in a and repr(a) or a for a in args)
+    return ' '.join(_mayberepr(a) for a in args)
 
 def dispatch(req):
     "run the command specified in req.args"