[PATCH] convert: normalize paths in convert (issue3612)

Mads Kiilerich mads at kiilerich.com
Wed Oct 17 00:29:20 UTC 2012


Huayang Guo wrote, On 10/16/2012 08:27 PM:
> # HG changeset patch
> # User Huayang <huayang at fb.com>
> # Date 1349479654 25200
> # Node ID 11816516e399001b058542827edeaf225327ec95
> # Parent  fa714f3ed2989aff64c267c9935251d9fc4f31ee
> convert: normalize paths in convert (issue3612)

convert: normalize paths in filemaps (issue3612)

>
> convert doesn't normalise double slashes in paths. Path normalizatin

normalization

> is applied when a path is loaded into filemap and when a file lookup
> request is isseud to filemap.

issued

>
> diff -r fa714f3ed298 -r 11816516e399 hgext/convert/filemap.py
> --- a/hgext/convert/filemap.py	Mon Oct 01 23:05:02 2012 -0500
> +++ b/hgext/convert/filemap.py	Fri Oct 05 16:27:34 2012 -0700
> @@ -4,6 +4,7 @@
>   # This software may be used and distributed according to the terms of the
>   # GNU General Public License version 2 or any later version.
>   
> +import os
>   import shlex
>   from mercurial.i18n import _
>   from mercurial import util
> @@ -16,6 +17,9 @@
>           e = name.rfind('/', 0, e)
>       yield '.', name
>   
> +def normalize(path):
> +    return os.path.normpath(path)

Introducing a new function just to wrap os.path.normpath seems like a 
bit of an overkill.

But more important: os.path.normpath will on windows also convert / to 
\. I doubt that will work.

(To repeat myself (for instance 
http://www.selenic.com/pipermail/mercurial-devel/2012-October/045291.html ): 
os.path is problematic and I think we should move away from it.)

A better quick solution would probably be to implement this normalize 
function yourself.

But in this case, in conversion code, I think it would be better to be 
strict and abort if any strange paths are found. YMMV.

In any case: This patch is missing a test.

/Mads




More information about the Mercurial-devel mailing list