Patchwork [2,of,8,py3] dispatch: extract maybe-use-repr formatting to helper function

login
register
mail settings
Submitter Augie Fackler
Date March 19, 2017, 6:11 a.m.
Message ID <18c8a3ed2c4da1367603.1489903893@imladris.local>
Download mbox | patch
Permalink /patch/19441/
State Accepted
Headers show

Comments

Augie Fackler - March 19, 2017, 6:11 a.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1489897286 14400
#      Sun Mar 19 00:21:26 2017 -0400
# Node ID 18c8a3ed2c4da13676038dccbf8359e00f55a5b1
# Parent  ea399732bc91813286b8f40082ec33a6a16b3558
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.

Patch

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -92,8 +92,13 @@  def _formatparse(write, inst):
     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"