[PATCH] convert: parse quoted keys and values in mapfiles

Yuya Nishihara yuya at tcha.org
Wed Sep 20 09:57:10 EDT 2017


On Mon, 18 Sep 2017 22:16:49 -0400, Matt Harbison wrote:
> On Mon, 18 Sep 2017 16:28:45 -0400, Ingmar Blonk <ingmar.blonk at gmail.com>  
> wrote:
> 
> > # HG changeset patch
> > # User Ingmar Blonk <ingmar.blonk at gmail.com>
> > # Date 1505662991 -7200
> > #      Sun Sep 17 17:43:11 2017 +0200
> > # Node ID af658bed1729dd0e48a60c67a82f4bc44f578c97
> > # Parent  448725a2ef7356524bcc9638a5c5eaaf59f263af
> > convert: parse quoted keys and values in mapfiles
> 
> This should probably be flagged as (BC), since it is changing documented  
> behavior.

Yes.

> It hasn't been documented for long though- I just updated it in  
> June (3a57bfd369d4).  Alternately, check the line to see if it contains  
> '"', to decide to split the old way or new way?  (Keep the old test too if  
> you go this route.)

I don't think we can fix this problem reliably without a BC, but maybe we
can try to preserve the old behavior if parsed line has more than two
tokens. And more conservative "wordchars" will minimize the behavior change.
See filemap.filemapper for example.

> > diff -r 448725a2ef73 -r af658bed1729 hgext/convert/common.py
> > --- a/hgext/convert/common.py    Fri Sep 15 00:01:57 2017 -0700
> > +++ b/hgext/convert/common.py    Sun Sep 17 17:43:11 2017 +0200
> > @@ -11,6 +11,7 @@
> >   import errno
> >   import os
> >   import re
> > +import shlex
> >   import subprocess
> >
> >   from mercurial.i18n import _
> > @@ -461,7 +462,7 @@
> >                   # Ignore blank lines
> >                   continue
> >               try:
> > -                key, value = line.rsplit(' ', 1)
> > +                key, value = shlex.split(line, posix=True)
> >               except ValueError:
> >                   raise error.Abort(
> >                       _('syntax error in %s(%d): key/value pair  
> > expected')

The mapfile class supports read and write, but this only changes the read
function, which doesn't make sense. Perhaps we should stop using the mapfile
class for branchmap and write a dedicated parse function.


More information about the Mercurial-devel mailing list