subrepos: handle backslashes in subpaths
authorMartin Geisler <mg@lazybytes.net>
Thu, 19 Aug 2010 13:25:46 +0200
changeset 11961 f3075ffa6b30
parent 11959 be33381882ad
child 11962 5f7ee3db3dd8
subrepos: handle backslashes in subpaths
mercurial/subrepo.py
tests/test-subrepo-paths.t
--- a/mercurial/subrepo.py	Wed Aug 18 11:59:35 2010 +0200
+++ b/mercurial/subrepo.py	Thu Aug 19 13:25:46 2010 +0200
@@ -50,6 +50,13 @@
             kind = kind[1:]
 
         for pattern, repl in p.items('subpaths'):
+            # Turn r'C:\foo\bar' into r'C:\\foo\\bar' since re.sub
+            # does a string decode.
+            repl = repl.encode('string-escape')
+            # However, we still want to allow back references to go
+            # through unharmed, so we turn r'\\1' into r'\1'. Again,
+            # extra escapes are needed because re.sub string decodes.
+            repl = re.sub(r'\\\\([0-9]+)', r'\\\1', repl)
             try:
                 src = re.sub(pattern, repl, src, 1)
             except re.error, e:
--- a/tests/test-subrepo-paths.t	Wed Aug 18 11:59:35 2010 +0200
+++ b/tests/test-subrepo-paths.t	Thu Aug 19 13:25:46 2010 +0200
@@ -13,14 +13,12 @@
 
 hg debugsub with remapping
 
-  $ cat > .hg/hgrc <<EOF
-  > [subpaths]
-  > http://example.net = ssh://localhost
-  > EOF
+  $ echo '[subpaths]' > .hg/hgrc
+  $ echo 'http://example.net/lib(.*) = C:\libs\\1-lib\' >> .hg/hgrc
 
   $ hg debugsub
   path sub
-   source   ssh://localhost/libfoo
+   source   C:\libs\foo-lib\
    revision 
 
 test bad subpaths pattern