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

mail settings
Submitter Katsunori FUJIWARA
Date May 5, 2014, 11:15 a.m.
Message ID <3d45c7ea3f9d7b40a86b.1399288556@juju>
Download mbox | patch
Permalink /patch/4631/
State Superseded
Headers show


Katsunori FUJIWARA - May 5, 2014, 11:15 a.m.
# HG changeset patch
# User FUJIWARA Katsunori <>
# 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

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/ b/mercurial/
--- a/mercurial/
+++ b/mercurial/
@@ -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"""