[PATCH 5 of 5 STABLE] subrepo: avoid "rstrip(os.sep)" for some problematic encodings on Windows

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Mon May 5 06:15:56 CDT 2014


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1399219546 -32400
#      Mon May 05 01:05:46 2014 +0900
# Branch stable
# Node ID 3d45c7ea3f9d7b40a86b3b5ec65065f1ff37fcd0
# Parent  76b049cd41f77aebf34e6ca65b73c367e3eee219
subrepo: avoid "rstrip(os.sep)" for some problematic encodings on Windows

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 which win32mbcs
extension focuses) on Windows, because some multi-byte characters in
such encodings contain '\\' (0x5c) as the second or latter byte of
them.

In such cases, "reporelpath()" leaves unexpected '\\' at the beginning
of the path returned to invokers.

In addition to it, "root" of "localrepository" object shouldn't have
"os.sep" at the end of it, because:

  (1) "localrepository.__init__()" always invokes "vfs.__init__()"
      with "realpath=True" as below, and

    def __init__(self, baseui, path=None, create=False):
        self.wvfs = scmutil.vfs(path, expandpath=True, realpath=True)
        ....
        self.root = self.wvfs.base

  (2) this makes "vfs.__init__()" normalize specified "base" by
      "os.path.realpath()" which trims "os.sep" at the end of
      specified path

    def __init__(self, base, audit=True, expandpath=False, realpath=False):
        ....
        if realpath:
            base = os.path.realpath(base)
        self.base = base

This patch avoids such meaningless "rstrip(os.sep)" in "reporelpath()"
for some problematic encodings on Windows.

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -276,8 +276,7 @@
     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(parent.root) + 1:]
 
 def subrelpath(sub):
     """return path to this subrepo as seen from outermost repo"""


More information about the Mercurial-devel mailing list