D5221: localrepo: extract loading of hgrc files to standalone function

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Tue Nov 6 07:27:59 EST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rHG473510bf0575: localrepo: extract loading of hgrc files to standalone function (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D5221?vs=12430&id=12448

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

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
@@ -451,14 +451,8 @@
     # 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)
-        # Run this before extensions.loadall() so extensions can be
-        # automatically enabled.
+    if loadhgrc(ui, wdirvfs, hgvfs, requirements):
         afterhgrcload(ui, wdirvfs, hgvfs, requirements)
-    except IOError:
-        pass
-    else:
         extensions.loadall(ui)
 
     # Set of module names of extensions loaded for this repository.
@@ -582,6 +576,24 @@
         features=features,
         intents=intents)
 
+def loadhgrc(ui, wdirvfs, hgvfs, requirements):
+    """Load hgrc files/content into a ui instance.
+
+    This is called during repository opening to load any additional
+    config files or settings relevant to the current repository.
+
+    Returns a bool indicating whether any additional configs were loaded.
+
+    Extensions should monkeypatch this function to modify how per-repo
+    configs are loaded. For example, an extension may wish to pull in
+    configs from alternate files or sources.
+    """
+    try:
+        ui.readconfig(hgvfs.join(b'hgrc'), root=wdirvfs.base)
+        return True
+    except IOError:
+        return False
+
 def afterhgrcload(ui, wdirvfs, hgvfs, requirements):
     """Perform additional actions after .hg/hgrc is loaded.
 



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


More information about the Mercurial-devel mailing list