Mercurial > public > mercurial-scm > hg
comparison mercurial/subrepo.py @ 21568:8dd17b19e722 stable
subrepo: normalize path in the specific way for problematic encodings
Before this patch, "reporelpath()" uses "rstrip(os.sep)" to trim
"os.sep" at the end of "parent.root" path.
But it doesn't work correctly with some problematic encodings on
Windows, because some multi-byte characters in such encodings contain
'\\' (0x5c) as the tail byte of them.
In such cases, "reporelpath()" leaves unexpected '\\' at the beginning
of the path returned to callers.
"lcalrepository.root" seems not to have tail "os.sep", because it is
always normalized by "os.path.realpath()" in "vfs.__init__()", but in
fact it has tail "os.sep", if it is a root (of the drive): path
normalization trims tail "os.sep" off "/foo/bar/", but doesn't trim
one off "/".
So, just avoiding "rstrip(os.sep)" in "reporelpath()" causes
regression around issue3033 fixed by fccd350acf79.
This patch introduces "pathutil.normasprefix" to normalize specified
path in the specific way for problematic encodings without regression
around issue3033.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Thu, 08 May 2014 19:03:00 +0900 |
parents | 5900bc09e684 |
children | 652e07debf10 |
comparison
equal
deleted
inserted
replaced
21567:5900bc09e684 | 21568:8dd17b19e722 |
---|---|
274 def reporelpath(repo): | 274 def reporelpath(repo): |
275 """return path to this (sub)repo as seen from outermost repo""" | 275 """return path to this (sub)repo as seen from outermost repo""" |
276 parent = repo | 276 parent = repo |
277 while util.safehasattr(parent, '_subparent'): | 277 while util.safehasattr(parent, '_subparent'): |
278 parent = parent._subparent | 278 parent = parent._subparent |
279 p = parent.root.rstrip(os.sep) | 279 return repo.root[len(pathutil.normasprefix(parent.root)):] |
280 return repo.root[len(p) + 1:] | |
281 | 280 |
282 def subrelpath(sub): | 281 def subrelpath(sub): |
283 """return path to this subrepo as seen from outermost repo""" | 282 """return path to this subrepo as seen from outermost repo""" |
284 if util.safehasattr(sub, '_relpath'): | 283 if util.safehasattr(sub, '_relpath'): |
285 return sub._relpath | 284 return sub._relpath |