Submitter | Szymon Wróblewski |
---|---|
Date | May 8, 2013, 7 p.m. |
Message ID | <ee9baf20baaf43ab70a9.1368039641@blue-pc> |
Download | mbox | patch |
Permalink | /patch/1590/ |
State | Accepted |
Commit | 8c2fdf7d56455eef10e8d4dadafd6dc3b367849a |
Headers | show |
Comments
On Wed, May 08, 2013 at 09:00:41PM +0200, Szymon Wroblewski wrote: > # HG changeset patch > # User Szymon Wroblewski <bluex0@gmail.com> > # Date 1368039356 -7200 > # Node ID ee9baf20baaf43ab70a972ab977a8a3cc5b9479f > # Parent 921b64e1f7b900cc58ffcc9b3fae4457bcb4d72b > splicemap: support paths with spaces in splicemap (issue3844) > > Shlex module was used to split line as suggested. Split operates in POSIX mode. > > diff -r 921b64e1f7b9 -r ee9baf20baaf hgext/convert/convcmd.py > --- a/hgext/convert/convcmd.py Wed May 01 10:42:03 2013 -0700 > +++ b/hgext/convert/convcmd.py Wed May 08 20:55:56 2013 +0200 > @@ -17,7 +17,7 @@ > from p4 import p4_source > import filemap > > -import os, shutil > +import os, shutil, shlex > from mercurial import hg, util, encoding > from mercurial.i18n import _ > > @@ -142,26 +142,22 @@ > if not line: > # Ignore blank lines > continue > - try: > - child, parents = line.split(' ', 1) > - self.source.checkrevformat(child) > - parents = parents.replace(',', ' ').split() > - # check if number of parents are upto 2 max > - if (len(parents) > 2): > - raise util.Abort(_('syntax error in %s(%d): child '\ > - 'parent1[,parent2] expected') \ > - % (path, i + 1)) > - for parent in parents: > - self.source.checkrevformat(parent) > - except ValueError: > - raise util.Abort(_('syntax error in %s(%d): child '\ > - 'parent1[,parent2] expected') \ > - % (path, i + 1)) > - pp = [] > - for p in parents: > - if p not in pp: > - pp.append(p) > - m[child] = pp > + # split line > + lex = shlex.shlex(line, posix=True) Will this work without posix mode? The posix flag here was introduced in Python 2.6 and we need to work on 2.4. > + lex.whitespace_split = True > + lex.whitespace += ',' > + line = list(lex) > + # check number of parents > + if not (2 <= len(line) <= 3): > + raise util.Abort(_('syntax error in %s(%d): child parent1' > + '[,parent2] expected') % (path, i + 1)) > + for part in line: > + self.source.checkrevformat(part) > + child, p1, p2 = line[0], line[1:2], line[2:] > + if p1 == p2: > + m[child] = p1 > + else: > + m[child] = p1 + p2 > # if file does not exist or error reading, exit > except IOError: > raise util.Abort(_('splicemap file not found or error reading %s:') > _______________________________________________ > Mercurial-devel mailing list > Mercurial-devel@selenic.com > http://selenic.com/mailman/listinfo/mercurial-devel
> Will this work without posix mode? The posix flag here was introduced > in Python 2.6 and we need to work on 2.4. It was introduced in 2.6 only for split function, shlex class had it already in 2.4. Moreover Kevin Bullock suggested, that parsing should work in posix mode, as it's used that way in filemap.
On May 9, 2013, at 11:00 AM, Szymon Wróblewski <bluex0@gmail.com> wrote: >> Will this work without posix mode? The posix flag here was introduced >> in Python 2.6 and we need to work on 2.4. > > It was introduced in 2.6 only for split function, shlex class had it > already in 2.4. > Moreover Kevin Bullock suggested, that parsing should work in posix > mode, as it's used that way in filemap. Ah, my mistake. Queued, thanks.
Patch
diff -r 921b64e1f7b9 -r ee9baf20baaf hgext/convert/convcmd.py --- a/hgext/convert/convcmd.py Wed May 01 10:42:03 2013 -0700 +++ b/hgext/convert/convcmd.py Wed May 08 20:55:56 2013 +0200 @@ -17,7 +17,7 @@ from p4 import p4_source import filemap -import os, shutil +import os, shutil, shlex from mercurial import hg, util, encoding from mercurial.i18n import _ @@ -142,26 +142,22 @@ if not line: # Ignore blank lines continue - try: - child, parents = line.split(' ', 1) - self.source.checkrevformat(child) - parents = parents.replace(',', ' ').split() - # check if number of parents are upto 2 max - if (len(parents) > 2): - raise util.Abort(_('syntax error in %s(%d): child '\ - 'parent1[,parent2] expected') \ - % (path, i + 1)) - for parent in parents: - self.source.checkrevformat(parent) - except ValueError: - raise util.Abort(_('syntax error in %s(%d): child '\ - 'parent1[,parent2] expected') \ - % (path, i + 1)) - pp = [] - for p in parents: - if p not in pp: - pp.append(p) - m[child] = pp + # split line + lex = shlex.shlex(line, posix=True) + lex.whitespace_split = True + lex.whitespace += ',' + line = list(lex) + # check number of parents + if not (2 <= len(line) <= 3): + raise util.Abort(_('syntax error in %s(%d): child parent1' + '[,parent2] expected') % (path, i + 1)) + for part in line: + self.source.checkrevformat(part) + child, p1, p2 = line[0], line[1:2], line[2:] + if p1 == p2: + m[child] = p1 + else: + m[child] = p1 + p2 # if file does not exist or error reading, exit except IOError: raise util.Abort(_('splicemap file not found or error reading %s:')