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

Simon King simon at simonking.org.uk
Tue Jul 14 10:37:55 CDT 2015


On Tue, Jul 14, 2015 at 4:25 PM, Eugene Baranov <eug.baranov at gmail.com> wrote:
> # 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)

The order of iteration over dictionaries is undefined. This means you
could potentially replace "%25" before one of the other characters,
which would cause an issue with a filename containing the sequence
"%252A" for example. Making "replacements" a list of tuples instead
would probably be safer.

Simon


More information about the Mercurial-devel mailing list