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

login
register
mail settings
Submitter Eugene Baranov
Date July 14, 2015, 4:24 p.m.
Message ID <f98f85d3a9bafc330873.1436891059@ADNADTX6400256.eng.citrite.net>
Download mbox | patch
Permalink /patch/9977/
State Superseded
Headers show

Comments

Eugene Baranov - July 14, 2015, 4:24 p.m.
# HG changeset patch
# User Eugene Baranov <eug.baranov@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
Matt Mackall - July 14, 2015, 8:10 p.m.
On Tue, 2015-07-14 at 17:24 +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 f98f85d3a9bafc3308735e7d1ac56e4c7b485f27
> # Parent  f516ac1d4b9bbbcd45763c1b008c805e60b8bfbf
> convert: unescape Perforce-escaped special characters in filenames

Queued for default, thanks. You might want to follow this up with a
doctest in decodefilename.

Patch

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]))