Patchwork [2,of,5,VFS] subrepo: add wvfs field to access the working directory via vfs

login
register
mail settings
Submitter Katsunori FUJIWARA
Date April 9, 2015, 3:51 p.m.
Message ID <da787532298df6df54b0.1428594675@juju>
Download mbox | patch
Permalink /patch/8577/
State Accepted
Commit dd0b86f740ef7789bfd5ef050371776b01ebe9bc
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 da787532298df6df54b0e188c1d5d4cb779a688e
# Parent  cf6135c3e2c7d3695e33e853d82d48aa53c0a041
subrepo: add wvfs field to access the working directory via vfs

This patch doesn't create vfs object in "abstractsubrepo.__init__()"
but adds propertycache-ed "wvfs" field, because the latter can:

  - delay vfs instantiation until it is actually needed

  - allow to use "hgsubrepo._repo.wvfs" as "wvfs"

    "hgsubrepo._repo" is initialized after
    "abstractsubrepo.__init__()" invocation, and passing
    "hgsubrepo._repo.wvfs" to "abstractsubrepo.__init__()" is
    difficult.

Patch

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -552,6 +552,12 @@  class abstractsubrepo(object):
     def shortid(self, revid):
         return revid
 
+    @propertycache
+    def wvfs(self):
+        """return vfs to access the working directory of this subrepository
+        """
+        return scmutil.vfs(self._ctx.repo().wvfs.join(self._path))
+
 class hgsubrepo(abstractsubrepo):
     def __init__(self, ctx, path, state):
         super(hgsubrepo, self).__init__(ctx, path)
@@ -944,6 +950,12 @@  class hgsubrepo(abstractsubrepo):
     def shortid(self, revid):
         return revid[:12]
 
+    @propertycache
+    def wvfs(self):
+        """return own wvfs for efficiency and consitency
+        """
+        return self._repo.wvfs
+
 class svnsubrepo(abstractsubrepo):
     def __init__(self, ctx, path, state):
         super(svnsubrepo, self).__init__(ctx, path)