D4566: localrepo: load extensions in makelocalrepository()

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Thu Sep 13 16:30:53 UTC 2018


indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Behavior does change subtly.
  
  First, we now load the hgrc before optionally setting up the vfs ward.
  That's fine: the vfs ward is for debugging and we know we won't hit it
  when reading .hg/hgrc. If the loaded extension were performing repo/vfs
  I/O, then we'd be worried. But extensions don't have access to the
  repo object that loaded them when they are loaded. Unless they are
  doing stack walking as part of module loading (which would be crazy),
  they shouldn't have access to the repo that incurred their load.
  
  Second, we now load extensions outside of the try..except IOError
  block. Previously, if loading an extension raised IOError, it would
  be silently ignored. I'm pretty sure the IOError is there for missing
  .hgrc files and should never have been ignored for issues loading
  extensions. I don't think this matters in reality because extension
  loading traps I/O errors.

REPOSITORY
  rHG Mercurial

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

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
@@ -397,6 +397,16 @@
     hgpath = wdirvfs.join(b'.hg')
     hgvfs = vfsmod.vfs(hgpath, cacheaudited=True)
 
+    # The .hg/hgrc file may load extensions or contain config options
+    # that influence repository construction. Attempt to load it and
+    # process any new extensions that it may have pulled in.
+    try:
+        ui.readconfig(hgvfs.join(b'hgrc'), root=wdirvfs.base)
+    except IOError:
+        pass
+    else:
+        extensions.loadall(ui)
+
     return localrepository(
         baseui=baseui,
         ui=ui,
@@ -507,11 +517,6 @@
         # Callback are in the form: func(repo, roots) --> processed root.
         # This list it to be filled by extension during repo setup
         self._phasedefaults = []
-        try:
-            self.ui.readconfig(self.vfs.join("hgrc"), self.root)
-            self._loadextensions()
-        except IOError:
-            pass
 
         if featuresetupfuncs:
             self.supported = set(self._basesupported) # use private copy
@@ -675,9 +680,6 @@
     def close(self):
         self._writecaches()
 
-    def _loadextensions(self):
-        extensions.loadall(self.ui)
-
     def _writecaches(self):
         if self._revbranchcache:
             self._revbranchcache.write()



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


More information about the Mercurial-devel mailing list