D4564: localrepo: move some vfs initialization out of __init__

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Tue Sep 18 17:59:35 EDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rHG2f9cdb5b3644: localrepo: move some vfs initialization out of __init__ (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D4564?vs=11002&id=11162

REVISION DETAIL
  https://phab.mercurial-scm.org/D4564

AFFECTED FILES
  mercurial/localrepo.py

CHANGE DETAILS

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -386,7 +386,18 @@
     The returned object conforms to the ``repository.completelocalrepository``
     interface.
     """
-    return localrepository(ui, path, intents=intents)
+    # Working directory VFS rooted at repository root.
+    wdirvfs = vfsmod.vfs(path, expandpath=True, realpath=True)
+
+    # Main VFS for .hg/ directory.
+    hgpath = wdirvfs.join(b'.hg')
+    hgvfs = vfsmod.vfs(hgpath, cacheaudited=True)
+
+    return localrepository(
+        ui, path,
+        wdirvfs=wdirvfs,
+        hgvfs=hgvfs,
+        intents=intents)
 
 @interfaceutil.implementer(repository.completelocalrepository)
 class localrepository(object):
@@ -438,30 +449,51 @@
         'bisect.state',
     }
 
-    def __init__(self, baseui, path, intents=None):
+    def __init__(self, baseui, origroot, wdirvfs, hgvfs, intents=None):
         """Create a new local repository instance.
 
-        Most callers should use ``hg.repository()`` or ``localrepo.instance()``
-        for obtaining a new repository object.
+        Most callers should use ``hg.repository()``, ``localrepo.instance()``,
+        or ``localrepo.makelocalrepository()`` for obtaining a new repository
+        object.
+
+        Arguments:
+
+        baseui
+           ``ui.ui`` instance to use. A copy will be made (since new config
+           options may be loaded into it).
+
+        origroot
+           ``bytes`` path to working directory root of this repository.
+
+        wdirvfs
+           ``vfs.vfs`` rooted at the working directory.
+
+        hgvfs
+           ``vfs.vfs`` rooted at .hg/
+
+        intents
+           ``set`` of system strings indicating what this repo will be used
+           for.
         """
+        self.baseui = baseui
+        self.ui = baseui.copy()
+        self.ui.copy = baseui.copy  # prevent copying repo configuration
+
+        self.origroot = origroot
+        # vfs rooted at working directory.
+        self.wvfs = wdirvfs
+        self.root = wdirvfs.base
+        # vfs rooted at .hg/. Used to access most non-store paths.
+        self.vfs = hgvfs
+        self.path = hgvfs.base
 
         self.requirements = set()
         self.filtername = None
-        # wvfs: rooted at the repository root, used to access the working copy
-        self.wvfs = vfsmod.vfs(path, expandpath=True, realpath=True)
-        # vfs: rooted at .hg, used to access repo files outside of .hg/store
-        self.vfs = None
         # svfs: usually rooted at .hg/store, used to access repository history
         # If this is a shared repository, this vfs may point to another
         # repository's .hg/store directory.
         self.svfs = None
-        self.root = self.wvfs.base
-        self.path = self.wvfs.join(".hg")
-        self.origroot = path
-        self.baseui = baseui
-        self.ui = baseui.copy()
-        self.ui.copy = baseui.copy # prevent copying repo configuration
-        self.vfs = vfsmod.vfs(self.path, cacheaudited=True)
+
         if (self.ui.configbool('devel', 'all-warnings') or
             self.ui.configbool('devel', 'check-locks')):
             self.vfs.audit = self._getvfsward(self.vfs.audit)
@@ -498,7 +530,7 @@
             except OSError as inst:
                 if inst.errno != errno.ENOENT:
                     raise
-            raise error.RepoError(_("repository %s not found") % path)
+            raise error.RepoError(_("repository %s not found") % origroot)
         else:
             try:
                 self.requirements = scmutil.readrequires(



To: indygreg, #hg-reviewers, durin42
Cc: durin42, mercurial-devel


More information about the Mercurial-devel mailing list