mercurial/localrepo.py
changeset 39852 2c2fadbc9851
parent 39850 d89d5bc06eaa
child 39854 823a580448d7
--- a/mercurial/localrepo.py	Wed Sep 19 13:48:59 2018 -0700
+++ b/mercurial/localrepo.py	Thu Sep 20 15:06:43 2018 -0700
@@ -446,6 +446,9 @@
     # 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.
+        afterhgrcload(ui, wdirvfs, hgvfs, requirements)
     except IOError:
         pass
     else:
@@ -572,6 +575,30 @@
         features=features,
         intents=intents)
 
+def afterhgrcload(ui, wdirvfs, hgvfs, requirements):
+    """Perform additional actions after .hg/hgrc is loaded.
+
+    This function is called during repository loading immediately after
+    the .hg/hgrc file is loaded and before per-repo extensions are loaded.
+
+    The function can be used to validate configs, automatically add
+    options (including extensions) based on requirements, etc.
+    """
+
+    # Map of requirements to list of extensions to load automatically when
+    # requirement is present.
+    autoextensions = {
+        b'lfs': [b'lfs'],
+    }
+
+    for requirement, names in sorted(autoextensions.items()):
+        if requirement not in requirements:
+            continue
+
+        for name in names:
+            if not ui.hasconfig(b'extensions', name):
+                ui.setconfig(b'extensions', name, b'', source='autoload')
+
 def gathersupportedrequirements(ui):
     """Determine the complete set of recognized requirements."""
     # Start with all requirements supported by this file.