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

Brett Cannon brett at python.org
Thu Mar 26 09:19:01 CDT 2015


On Thu, Mar 26, 2015 at 10:01 AM Yuya Nishihara <yuya at tcha.org> wrote:

> 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]
> **********************************************************************
>
>
Are doctests typically used?
http://mercurial.selenic.com/wiki/ContributingChanges doesn't mention them
and I would assume that if they were important they would be integrated
into the test.py script in hglib.

Regardless, how does this get fixed? Does this cause all of my patches to
get rejected and thus I have to go back and re-submit all of them? Does
Matt apply the other patches that don't break anything, skip the ones that
do, and then I re-submit just the ones that got rejected?


> > +        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() ?
>

It might work. strtobytes() post-dates all of these changes in my ported
local repo so I just didn't think about it. It's quite possible it will fix
this problem and negate the need to special-case int.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20150326/86f84a18/attachment.html>


More information about the Mercurial-devel mailing list