[PATCH] splicemap: support for path with spaces in splicemap (issue3844)

Szymon Wróblewski bluex0 at gmail.com
Wed May 1 04:28:03 CDT 2013


# HG changeset patch
# User Szymon Wroblewski <bluex0 at gmail.com>
# Date 1367400018 -7200
# Branch stable
# Node ID 8a8366a088e27de1853026a6dcea90b596304e7c
# Parent  fc081623f4bd918e384b47231707a4ee71dc1ccf
splicemap: support paths with spaces in splicemap (issue3844)

Shlex module was used to split line as suggested. Split operates in
non-POSIX
mode to support backslash in path on Windows.

Variable p was added to raise IndexError if there isn't at least one parent.

diff -r fc081623f4bd -r 8a8366a088e2 hgext/convert/common.py
--- a/hgext/convert/common.py Mon Apr 29 14:14:42 2013 -0700
+++ b/hgext/convert/common.py Wed May 01 11:20:18 2013 +0200
@@ -5,7 +5,7 @@
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.

-import base64, errno, subprocess, os, datetime
+import base64, errno, subprocess, os, datetime, shlex
 import cPickle as pickle
 from mercurial import util
 from mercurial.i18n import _
@@ -437,9 +437,9 @@
                 # Ignore blank lines
                 continue
             try:
-                child, parents = line.split(' ', 1)
-                parents = parents.replace(',', ' ').split()
-            except ValueError:
+                line = shlex.split(line.replace(',', ' '), posix=False)
+                child, parents, p = line[0], line[1:], line[1]
+            except IndexError:
                 raise util.Abort(_('syntax error in %s(%d): child parent1'
                                    '[,parent2] expected') % (path, i + 1))
             pp = []
diff -r fc081623f4bd -r 8a8366a088e2 tests/test-convert-splicemap.t
--- a/tests/test-convert-splicemap.t Mon Apr 29 14:14:42 2013 -0700
+++ b/tests/test-convert-splicemap.t Wed May 01 11:20:18 2013 +0200
@@ -220,3 +220,35 @@
   scanning source...
   abort: unknown splice map parent:
deadbeef102a90ea7b4a3361e4082ed620918c26
   [255]
+
+Test parsesplicemap
+
+  >>> from hgext.convert.common import parsesplicemap
+  >>> lines = r'''
+  ...   /dummy/path/child /dummy/path/parent1, /dummy/path/parent2
+  ...   /dummy/path/child /dummy/path/parent1 /dummy/path/parent2
+  ...   "/dummy/s p a c e/child" "/dummy/s p a c e/p1" "/dummy/s p a c
e/p2"
+  ...   C:\dummy\path\child C:\dummy\path\parent1, C:\dummy\path\parent2
+  ...   C:\dummy\path\child C:\dummy\path\parent1 C:\dummy\path\parent2
+  ...   "C:\dummy\s p a c e\child" "C:\dummy\s p a c e\p1" "C:\dummy\s p a
c e\p2"
+  ...   /dummy/path/child
+  ...   "C:\dummy\s p a c e\child"
+  ... '''
+  >>> lines = [line.strip() for line in lines.splitlines() if line]
+  >>> for i, line in enumerate(lines):
+  ...   fn = 'splicemap%d' % i
+  ...   fp = open(fn, 'w')
+  ...   fp.write(line.strip())
+  ...   fp.close()
+  ...   try:
+  ...     print parsesplicemap(fn)
+  ...   except Exception as e:
+  ...     print '%s: %s' % (e.__class__.__name__, e)
+  {'/dummy/path/child': ['/dummy/path/parent1', '/dummy/path/parent2']}
+  {'/dummy/path/child': ['/dummy/path/parent1', '/dummy/path/parent2']}
+  {'"/dummy/s p a c e/child"': ['"/dummy/s p a c e/p1"', '"/dummy/s p a c
e/p2"']}
+  {'C:\\dummy\\path\\child': ['C:\\dummy\\path\\parent1',
'C:\\dummy\\path\\parent2']}
+  {'C:\\dummy\\path\\child': ['C:\\dummy\\path\\parent1',
'C:\\dummy\\path\\parent2']}
+  {'"C:\\dummy\\s p a c e\\child"': ['"C:\\dummy\\s p a c e\\p1"',
'"C:\\dummy\\s p a c e\\p2"']}
+  Abort: syntax error in splicemap6(1): child parent1[,parent2] expected
+  Abort: syntax error in splicemap7(1): child parent1[,parent2] expected



2013/4/30 Matt Mackall <mpm at selenic.com>

> On Tue, 2013-04-30 at 01:09 +0200, Szymon Wróblewski wrote:
> > This should be enough, if behavior depending on os is acceptable.
> >
> > # HG changeset patch
> > # User Szymon Wroblewski <bluex0 at gmail.com>
> > # Date 1367276230 -7200
> > # Branch stable
> > # Node ID 1291d5db2a88fe4b42817802385d5c462a86876b
> > # Parent  f01a351db79106ba96ac6d527cf69944fd98e665
> > splicemap: support paths with spaces in splicemap (issue3844)
> >
> > Shlex module was used to split line as suggested. Split behavior depends
> on
> > os
> > (to support backslash in path on windows).
>
> So here's what that posix switch does:
>
> http://docs.python.org/2.7/library/shlex.html#parsing-rules
>
> In short.. it's completely different. Having the parsing rules be
> completely different is suboptimal. We might want to instead have posix
> mode always off.
>
> This wants some test cases added to the existing splicemap test.
>
> --
> Mathematics is the supreme nostalgia of our time.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20130501/a1412ba8/attachment.html>


More information about the Mercurial-devel mailing list