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

Eugene Baranov eug.baranov at gmail.com
Tue Jul 14 11:24:19 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 f98f85d3a9bafc3308735e7d1ac56e4c7b485f27
# Parent  f516ac1d4b9bbbcd45763c1b008c805e60b8bfbf
convert: unescape Perforce-escaped special characters in filenames

diff -r f516ac1d4b9b -r f98f85d3a9ba 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:
+        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