Patchwork [v3] convert: unescape Perforce-escaped special characters in filenames

login
register
mail settings
Submitter Eugene Baranov
Date July 15, 2015, 9:51 a.m.
Message ID <528c1d146a0d2f079f01.1436953892@ADNADTX6400256.eng.citrite.net>
Download mbox | patch
Permalink /patch/9988/
State Accepted
Commit a36fd0993522a8097e116d5d806a06b5ac88d6f7
Headers show

Comments

Eugene Baranov - July 15, 2015, 9:51 a.m.
# HG changeset patch
# User Eugene Baranov <eug.baranov@gmail.com>
# Date 1436887437 -3600
#      Tue Jul 14 16:23:57 2015 +0100
# Node ID 528c1d146a0d2f079f01b81771140e3d8ed066e6
# Parent  35fa7c77c754aa4d156c42abfdb61ca178468872
convert: unescape Perforce-escaped special characters in filenames
Matt Mackall - July 15, 2015, 9:46 p.m.
On Wed, 2015-07-15 at 10:51 +0100, Eugene Baranov wrote:
> # HG changeset patch
> # User Eugene Baranov <eug.baranov@gmail.com>
> # Date 1436887437 -3600
> #      Tue Jul 14 16:23:57 2015 +0100
> # Node ID 528c1d146a0d2f079f01b81771140e3d8ed066e6
> # Parent  35fa7c77c754aa4d156c42abfdb61ca178468872
> convert: unescape Perforce-escaped special characters in filenames

I've rolled this one into the previously-accepted patch, thanks.

Patch

diff -r 35fa7c77c754 -r 528c1d146a0d hgext/convert/p4.py
--- a/hgext/convert/p4.py	Sun Jul 12 17:59:25 2015 +0900
+++ 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]))
diff -r 35fa7c77c754 -r 528c1d146a0d tests/test-doctest.py
--- a/tests/test-doctest.py	Sun Jul 12 17:59:25 2015 +0900
+++ 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')