changeset 25788:a36fd0993522

convert: unescape Perforce-escaped special characters in filenames
author Eugene Baranov <eug.baranov@gmail.com>
date Tue, 14 Jul 2015 16:23:57 +0100
parents d9133e89d39d
children 95dc4b009f60
files hgext/convert/p4.py tests/test-doctest.py
diffstat 2 files changed, 16 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/convert/p4.py	Mon Jul 13 21:37:46 2015 -0700
+++ b/hgext/convert/p4.py	Tue Jul 14 16:23:57 2015 +0100
@@ -23,6 +23,20 @@
     except EOFError:
         pass
 
+def decodefilename(filename):
+    """Perforce escapes special characters @, #, *, or %
+    with %40, %23, %2A, or %25 respectively
+
+    >>> decodefilename('portable-net45%252Bnetcore45%252Bwp8%252BMonoAndroid')
+    'portable-net45%2Bnetcore45%2Bwp8%2BMonoAndroid'
+    >>> decodefilename('//Depot/Directory/%2525/%2523/%23%40.%2A')
+    '//Depot/Directory/%25/%23/#@.*'
+    """
+    replacements = [('%2A', '*'), ('%23', '#'), ('%40', '@'), ('%25', '%')]
+    for k, v in replacements:
+        filename = filename.replace(k, v)
+    return filename
+
 class p4_source(converter_source):
     def __init__(self, ui, path, revs=None):
         super(p4_source, self).__init__(ui, path, revs=revs)
@@ -138,7 +152,7 @@
                 filename = None
                 for v in vieworder:
                     if oldname.lower().startswith(v.lower()):
-                        filename = views[v] + oldname[len(v):]
+                        filename = decodefilename(views[v] + oldname[len(v):])
                         break
                 if filename:
                     files.append((filename, d["rev%d" % i]))
--- a/tests/test-doctest.py	Mon Jul 13 21:37:46 2015 -0700
+++ b/tests/test-doctest.py	Tue Jul 14 16:23:57 2015 +0100
@@ -33,5 +33,6 @@
 testmod('mercurial.util', testtarget='platform')
 testmod('hgext.convert.cvsps')
 testmod('hgext.convert.filemap')
+testmod('hgext.convert.p4')
 testmod('hgext.convert.subversion')
 testmod('hgext.mq')