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

login
register
mail settings
Submitter Katsunori FUJIWARA
Date April 9, 2015, 3:51 p.m.
Message ID <f058247059f549cbeead.1428594676@juju>
Download mbox | patch
Permalink /patch/8575/
State Accepted
Commit 105758d1b37b29d243d8807953c20f12dbcfdecd
Headers show

Comments

Katsunori FUJIWARA - April 9, 2015, 3:51 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@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".

Patch

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()