[PATCH] subrepo: fix path normalization

Patrick Mezard pmezard at gmail.com
Mon May 16 16:59:01 CDT 2011

# 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)
 def _abssource(repo, push=False, abort=True):
     """return pull/push path of repo - either based on parent repo .hgsub info
     or on the top repo config. Abort or return None if no source found."""
     if hasattr(repo, '_subparent'):
         source = util.url(repo._subsource)
-        source.path = posixpath.normpath(source.path)
+        _normpath(source)
         if posixpath.isabs(source.path) or source.scheme:
             return str(source)
         parent = _abssource(repo._subparent, push, abort=False)
         if parent:
             parent = util.url(parent)
             parent.path = posixpath.join(parent.path, source.path)
-            parent.path = posixpath.normpath(parent.path)
+            _normpath(parent)
             return str(parent)
     else: # recursion reached top repo
         if hasattr(repo, '_subtoppath'):

More information about the Mercurial-devel mailing list