[PATCH] dispatch: strip command line options like config file options

Yuya Nishihara yuya at tcha.org
Thu Feb 11 22:52:15 EST 2016


On Thu, 11 Feb 2016 23:25:10 +0000, Tony Tung wrote:
> > On Feb 11, 2016, at 2:09 AM, Yuya Nishihara <yuya at tcha.org> wrote:
> > 
> > On Thu, 11 Feb 2016 08:06:40 +0000, Tony Tung wrote:
> >>> On Feb 10, 2016, at 11:49 PM, Yuya Nishihara <yuya at tcha.org> wrote:
> >>> 
> >>> On Mon, 8 Feb 2016 15:36:15 -0800, Tony Tung wrote:
> >>>> # HG changeset patch
> >>>> # User Tony Tung <ttung at fb.com>
> >>>> # Date 1454974530 28800
> >>>> #      Mon Feb 08 15:35:30 2016 -0800
> >>>> # Node ID 97240c9addb84f73752dad57e6531dfea30f3f0d
> >>>> # Parent  01a5143cd25f285f8c745a92986cd7186bb32c90
> >>>> dispatch: strip command line options like config file options.
> >>>> 
> >>>> Currently, whitespace in command line --config options are considered
> >>>> significant while whitespace in config files are not considered
> >>>> significant.  This diff strips the leading and trailing whitespace from
> >>>> command line config options.
> >>>> 
> >>>> diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
> >>>> --- a/mercurial/dispatch.py
> >>>> +++ b/mercurial/dispatch.py
> >>>> @@ -609,7 +609,8 @@
> >>>> 
> >>>>    for cfg in config:
> >>>>        try:
> >>>> -            name, value = cfg.split('=', 1)
> >>>> +            name, value = [cfgelem.strip()
> >>>> +                           for cfgelem in cfg.split('=', 1)]
> >>> 
> >>> I think that's up to parser whether white space is significant or not.
> >> 
> >> The parser definitely has a say into the significance of the outer
> >> whitespaces, but it has no visibility into the inner whitespaces,
> >> i.e., the spaces surrounding the =.
> > 
> > I'm not sure if I understand what you mean. I wanted to tell that
> > --config is parsed as a command-line option, which rule can be different
> > from a config file. And if --config contains a whitespace, it would be
> > considered explicitly specified.
> > 
> >  --config foo.bar="baz "
> > 
> > That said, because config key shouldn't start/end with space,
> > --config " foo . bar "=baz might be an error.
> 
> Why is explicit whitespace in a config file treated differently than explicit
> whitespace in the command line?

Well, I don't have strong reasoning, sorry. I just feel stripping whitespaces
in command argument is different thing than stripping whitespaces while parsing
config file. Perhaps one reason is command arguments are first parsed by the
shell.

And I thought ' section . name '=value might be invalid because _parseconfig()
says "use --config section.name=value".


More information about the Mercurial-devel mailing list