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

Eugene Baranov eug.baranov at gmail.com
Tue Jul 14 10:25:31 CDT 2015


# HG changeset patch
# User Eugene Baranov <eug.baranov at gmail.com>
# Date 1436887437 -3600
#      Tue Jul 14 16:23:57 2015 +0100
# Node ID 3908871b636316c592c2b911b7f1e7ad5ae764b4
# Parent  f516ac1d4b9bbbcd45763c1b008c805e60b8bfbf
convert: unescape Perforce-escaped special characters in filenames

diff -r f516ac1d4b9b -r 3908871b6363 hgext/convert/p4.py
--- a/hgext/convert/p4.py	Tue Jul 14 14:40:56 2015 +0100
+++ b/hgext/convert/p4.py	Tue Jul 14 16:23:57 2015 +0100
@@ -23,6 +23,14 @@
     except EOFError:
         pass
 
+def decodefilename(filename):
+    '''Perforce escapes special characters @, #, *, or %
+    with %40, %23, %2A, or %25 respectively'''
+    replacements = { '%2A': '*', '%23' : '#', '%40' : '@', '%25' : '%'}
+    for k, v in replacements.iteritems():
+        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 +146,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]))


More information about the Mercurial-devel mailing list