changeset 24835:e4f75c93f073 stable

unionrepo: use pathutil.normasprefix to ensure os.sep at the end of cwd Since Python 2.7.9, "os.path.join(path, '')" doesn't add "os.sep" at the end of UNC path (see issue4557 for detail). This makes unionrepo incorrectly work, if: 1. cwd is the root of UNC share (e.g. "\host\share"), and 2. mainreporoot is near cwd (e.g. "\host\sharefoo\repo") - host of UNC path is same as one of cwd - share of UNC path starts with one of cwd 3. "repopath" isn't specified in URI (e.g. "union:path/to/repo2") For example: $ hg --cwd \host\share -R \host\sharefoo\repo incoming union:path\to\repo2 In this case: - os.path.join(r"\host\share", "") returns r"\host\share", - r"\host\sharefoo\repo".startswith(r"\host\share") returns True, then - r"foo\repo" is treated as repopath of unionrepo instead of r"\host\sharefoo\repo" This causes failure of combining "\host\sharefoo\repo" and another repository: in addition to it, "\host\share\foo\repo" may be combined with another repository, if it accidentally exists. This patch uses "pathutil.normasprefix()" to ensure "os.sep" at the end of cwd safely, even with some problematic encodings, which use 0x5c (= "os.sep" on Windows) as the tail byte of some multi-byte characters. BTW, normalization before "pathutil.normasprefix()" isn't needed in this case, because "os.getcwd()" always returns normalized one.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Wed, 22 Apr 2015 23:38:55 +0900
parents 6e31e1274080
children 1f9127c9239b
files mercurial/unionrepo.py
diffstat 1 files changed, 2 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/unionrepo.py	Wed Apr 22 23:38:55 2015 +0900
+++ b/mercurial/unionrepo.py	Wed Apr 22 23:38:55 2015 +0900
@@ -15,7 +15,7 @@
 from i18n import _
 import os
 import util, mdiff, cmdutil, scmutil
-import localrepo, changelog, manifest, filelog, revlog
+import localrepo, changelog, manifest, filelog, revlog, pathutil
 
 class unionrevlog(revlog.revlog):
     def __init__(self, opener, indexfile, revlog2, linkmapper):
@@ -228,7 +228,7 @@
         if parentpath == cwd:
             parentpath = ''
         else:
-            cwd = os.path.join(cwd,'')
+            cwd = pathutil.normasprefix(cwd)
             if parentpath.startswith(cwd):
                 parentpath = parentpath[len(cwd):]
     if path.startswith('union:'):