[PATCH 4 of 7 hglib] hglib: make util.cmdbuilder work with bytes (issue4520)

Yuya Nishihara yuya at tcha.org
Thu Mar 26 08:59:36 CDT 2015


On Wed, 25 Mar 2015 20:39:58 -0400, Brett Cannon wrote:
> # HG changeset patch
> # User Brett Cannon <brett at python.org>
> # Date 1427329317 14400
> #      Wed Mar 25 20:21:57 2015 -0400
> # Node ID 5efe91a4c2d49d74d1104edd50cd5a82003df4b6
> # Parent  6d273d0a51aa24f9c837d67b656467f98f98786d
> hglib: make util.cmdbuilder work with bytes (issue4520)
> 
> diff -r 6d273d0a51aa -r 5efe91a4c2d4 hglib/util.py
> --- a/hglib/util.py	Wed Mar 25 20:19:09 2015 -0400
> +++ b/hglib/util.py	Wed Mar 25 20:21:57 2015 -0400
> @@ -103,7 +103,7 @@
>          if val is None:
>              continue
>  
> -        arg = arg.replace(b('_'), b('-'))
> +        arg = b(arg).replace(b('_'), b('-'))
>          if arg != b('-'):
>              if len(arg) == 1:
>                  arg = b('-') + arg
> @@ -115,10 +115,13 @@
>          elif isinstance(val, list):
>              for v in val:
>                  cmd.append(arg)
> -                cmd.append(str(v))
> +                cmd.append(v)

Doctest fails here.

% python -m doctest hglib/util.py
**********************************************************************
File "hglib/util.py", line 97, in util.cmdbuilder
Failed example:
    cmdbuilder('cmd', list=[1, 2])
Expected:
    ['cmd', '--list', '1', '--list', '2']
Got:
    ['cmd', '--list', 1, '--list', 2]
**********************************************************************

> +        elif isinstance(val, int):
> +            cmd.append(arg)
> +            cmd.append(strtobytes(val))
>          else:
>              cmd.append(arg)
> -            cmd.append(str(val))
> +            cmd.append(val)

Why not just replace str() by strtobytes() ?


More information about the Mercurial-devel mailing list