[PATCH 3 of 5 VFS] subrepo: add _relpath field to centralize subrelpath logic

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Thu Apr 9 10:51:16 CDT 2015


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1428593802 -32400
#      Fri Apr 10 00:36:42 2015 +0900
# Node ID f058247059f549cbeeaddc0f1891b41575c75d0c
# Parent  da787532298df6df54b0e188c1d5d4cb779a688e
subrepo: add _relpath field to centralize subrelpath logic

This patch adds propertycache-ed "_relpath" field to
"abstractsubrepo", to centralize "subrelpath" logic into it.

Now, "subrelpath()" can always return "_relpath" field of the
specified subrepo object, because it is ensured that subrepo object
has it. To reduce changes in this patch, "subrelpath()" itself is
still kept, even though it seems to be redundant.

This is also a part of eliminating "os.path.*" API invocations for
"Windows UTF-8 Plan".

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -280,11 +280,7 @@ def reporelpath(repo):
 
 def subrelpath(sub):
     """return path to this subrepo as seen from outermost repo"""
-    if util.safehasattr(sub, '_relpath'):
-        return sub._relpath
-    if not util.safehasattr(sub, '_repo'):
-        return sub._path
-    return reporelpath(sub._repo)
+    return sub._relpath
 
 def _abssource(repo, push=False, abort=True):
     """return pull/push path of repo - either based on parent repo .hgsub info
@@ -558,6 +554,12 @@ class abstractsubrepo(object):
         """
         return scmutil.vfs(self._ctx.repo().wvfs.join(self._path))
 
+    @propertycache
+    def _relpath(self):
+        """return path to this subrepository as seen from outermost repository
+        """
+        return self.wvfs.reljoin(reporelpath(self._ctx.repo()), self._path)
+
 class hgsubrepo(abstractsubrepo):
     def __init__(self, ctx, path, state):
         super(hgsubrepo, self).__init__(ctx, path)
@@ -1188,7 +1190,6 @@ class gitsubrepo(abstractsubrepo):
     def __init__(self, ctx, path, state):
         super(gitsubrepo, self).__init__(ctx, path)
         self._state = state
-        self._relpath = os.path.join(reporelpath(ctx.repo()), path)
         self._abspath = ctx.repo().wjoin(path)
         self._subparent = ctx.repo()
         self._ensuregit()


More information about the Mercurial-devel mailing list