Patchwork [3,of,8,py3] dispatch: ensure repr is bytes in _mayberepr

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

Comments

Augie Fackler - March 19, 2017, 6:11 a.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1489897324 14400
#      Sun Mar 19 00:22:04 2017 -0400
# Node ID 6823ee960b6e67f6fb6e91f6266b060deac8e7d0
# Parent  18c8a3ed2c4da13676038dccbf8359e00f55a5b1
dispatch: ensure repr is bytes in _mayberepr

Fixes command line arguments containing spaces on Python 3.
Yuya Nishihara - March 19, 2017, 2:45 p.m.
On Sun, 19 Mar 2017 02:11:34 -0400, Augie Fackler wrote:
> # HG changeset patch
> # User Augie Fackler <augie@google.com>
> # Date 1489897324 14400
> #      Sun Mar 19 00:22:04 2017 -0400
> # Node ID 6823ee960b6e67f6fb6e91f6266b060deac8e7d0
> # Parent  18c8a3ed2c4da13676038dccbf8359e00f55a5b1
> dispatch: ensure repr is bytes in _mayberepr

Queued, but found a nit.

> --- a/mercurial/dispatch.py
> +++ b/mercurial/dispatch.py
> @@ -94,7 +94,7 @@ def _formatparse(write, inst):
>  
>  def _mayberepr(a):
>      if ' ' in a:
> -        return repr(a)
> +        return encoding.strtolocal(repr(a))

repr() of bytes has b'' prefix on Python 3, which wouldn't be what we want.
Maybe we can use util.shellquote() to format command args.

Patch

diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -94,7 +94,7 @@  def _formatparse(write, inst):
 
 def _mayberepr(a):
     if ' ' in a:
-        return repr(a)
+        return encoding.strtolocal(repr(a))
     return a
 
 def _formatargs(args):