This revision was automatically updated to reflect the committed changes.
Closed by commit rHG2c2fadbc9851: localrepo: automatically load lfs extension 
when required (BC) (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D4711?vs=11319&id=11383

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

AFFECTED FILES
  mercurial/localrepo.py
  tests/test-lfs.t

CHANGE DETAILS

diff --git a/tests/test-lfs.t b/tests/test-lfs.t
--- a/tests/test-lfs.t
+++ b/tests/test-lfs.t
@@ -1,5 +1,52 @@
 #require no-reposimplestore no-chg
 
+  $ hg init requirements
+  $ cd requirements
+
+# LFS not loaded by default.
+
+  $ hg config extensions
+  [1]
+
+# Adding lfs to requires file will auto-load lfs extension.
+
+  $ echo lfs >> .hg/requires
+  $ hg config extensions
+  extensions.lfs=
+
+# But only if there is no config entry for the extension already.
+
+  $ cat > .hg/hgrc << EOF
+  > [extensions]
+  > lfs=!
+  > EOF
+
+  $ hg config extensions
+  abort: repository requires features unknown to this Mercurial: lfs!
+  (see https://mercurial-scm.org/wiki/MissingRequirement for more information)
+  [255]
+
+  $ cat > .hg/hgrc << EOF
+  > [extensions]
+  > lfs=
+  > EOF
+
+  $ hg config extensions
+  extensions.lfs=
+
+  $ cat > .hg/hgrc << EOF
+  > [extensions]
+  > lfs = missing.py
+  > EOF
+
+  $ hg config extensions
+  *** failed to import extension lfs from missing.py: [Errno 2] $ENOENT$: 
'missing.py'
+  abort: repository requires features unknown to this Mercurial: lfs!
+  (see https://mercurial-scm.org/wiki/MissingRequirement for more information)
+  [255]
+
+  $ cd ..
+
 # Initial setup
 
   $ cat >> $HGRCPATH << EOF
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -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.



To: indygreg, #hg-reviewers, mharbison72
Cc: mharbison72, mercurial-devel
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to