localrepo: load extensions in makelocalrepository()
authorGregory Szorc <gregory.szorc@gmail.com>
Wed, 12 Sep 2018 11:44:57 -0700
changeset 39690 e0c5017124b3
parent 39689 f19bba3f4d3f
child 39691 2f067e365532
localrepo: load extensions in makelocalrepository() 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. Differential Revision: https://phab.mercurial-scm.org/D4566
mercurial/localrepo.py
--- a/mercurial/localrepo.py	Wed Sep 12 11:34:02 2018 -0700
+++ b/mercurial/localrepo.py	Wed Sep 12 11:44:57 2018 -0700
@@ -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()