Comments
Patch
@@ -142,3 +142,25 @@ def canonpath(root, cwd, myname, auditor
name = dirname
raise util.Abort(_("%s not under root '%s'") % (myname, root))
+
+def normasprefix(path):
+ '''normalize the specified path as path prefix
+
+ Returned vaule can be used safely for "p.startswith(prefix)",
+ "p[len(prefix):]", and so on.
+
+ For efficiency, this expects "path" argument to be already
+ normalized by "os.path.normpath", "os.path.realpath", and so on.
+
+ See also issue3033 for detail about need of this function.
+
+ >>> normasprefix('/foo/bar').replace(os.sep, '/')
+ '/foo/bar/'
+ >>> normasprefix('/').replace(os.sep, '/')
+ '/'
+ '''
+ d, p = os.path.splitdrive(path)
+ if len(p) != len(os.sep):
+ return path + os.sep
+ else:
+ return path
@@ -276,8 +276,7 @@ def reporelpath(repo):
parent = repo
while util.safehasattr(parent, '_subparent'):
parent = parent._subparent
- p = parent.root.rstrip(os.sep)
- return repo.root[len(p) + 1:]
+ return repo.root[len(pathutil.normasprefix(parent.root)):]
def subrelpath(sub):
"""return path to this subrepo as seen from outermost repo"""
@@ -19,6 +19,7 @@ testmod('mercurial.hg')
testmod('mercurial.hgweb.hgwebdir_mod')
testmod('mercurial.match')
testmod('mercurial.minirst')
+testmod('mercurial.pathutil')
testmod('mercurial.revset')
testmod('mercurial.store')
testmod('mercurial.subrepo')