[PATCH] subrepo: fix path normalization

Patrick Mézard pmezard at gmail.com
Tue May 17 06:25:44 CDT 2011


Le 17/05/11 00:07, Matt Mackall a écrit :
> On Tue, 2011-05-17 at 00:01 +0200, Patrick Mézard wrote:
>> Le 16/05/11 23:59, Patrick Mezard a écrit :
>>> # HG changeset patch
>>> # User Patrick Mezard <pmezard at gmail.com>
>>> # Date 1305582739 -7200
>>> # Node ID 8a48103713fc7277521b8e6402dfdea054a3dc20
>>> # Parent  defa319d8bb7cea6a588e453cd4be4b467af8c47
>>> subrepo: fix path normalization
>>>
>>> Calling posixpath.normpath() on a Windows path does not work as expected:
>>>
>>>   >> posixpath.normpath('c:\\foo\\bar/../baz')
>>>   >> 'baz'
>>>
>>> Either the path should be first normalized to have a slash as separator, or
>>> they should be handled by platform specific normalization routines.
>>>
>>> diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
>>> --- a/mercurial/subrepo.py
>>> +++ b/mercurial/subrepo.py
>>> @@ -190,19 +190,25 @@
>>>          return sub._path
>>>      return reporelpath(sub._repo)
>>>  
>>> +def _normpath(url):
>>> +    if any((url.scheme, url.host, url.user, url.passwd)):
>>> +        url.path = posixpath.normpath(url.path)
>>> +    else:
>>> +        url.path = os.path.normpath(url.path)
>>> +
>>
>> I considered turning this into a url method but none of them currently
>> mutate the object and it might be confusing to have a non-mutable
>> localpath() and a mutable normpath().
> 
> Does this fix the recently reported regression with UNC paths?

No, it does not, it fixes a breakage in the nested_relative test part of test-subrepo.t I detected yesterday. The UNC path handling is still broken because we use posixpath.join() with an absolute regular path and an absolute UNC path, and it does not overwrite the first with the second one which os.path.join() does. There are additional failures in the following hg.clone() call probably related to the point you made about handing UNC paths in file:// URLs.

I will try to take a look at this.
 
> If we were to touch the url class here, it would be to force it to
> canonicalize slashes.

I am not sure this will solve the UNC case as I suspect ntpath.join() has some intelligence when dealing with calls like:

join("c:\\foo\\bar", "\\\\server\\path")

to know the second path is an absolute path.
 
> I don't think there's any reasonable way to combine UNC paths with file:
> URLs. Though maybe I'm wrong here:
> 
> http://stackoverflow.com/questions/2773922/asp-net-convert-unc-to-file-url
> 
> (five slashes!)

--
Patrick Mézard



More information about the Mercurial-devel mailing list