[PATCH] subrepo: fix path normalization

Matt Mackall mpm at selenic.com
Mon May 16 17:07:54 CDT 2011


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?

If we were to touch the url class here, it would be to force it to
canonicalize slashes.

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

-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list