[Updated] D11823: extensions: add a default "*" suboptions prefix

marmoute (Pierre-Yves David) phabricator at mercurial-scm.org
Tue Nov 30 15:13:24 UTC 2021


Closed by commit rHG7e6488aa1261: extensions: add a default "*" suboptions prefix (authored by marmoute).
This revision was automatically updated to reflect the committed changes.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D11823?vs=31194&id=31210

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D11823/new/

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

AFFECTED FILES
  mercurial/extensions.py
  mercurial/helptext/config.txt
  tests/test-check-module-imports.t
  tests/test-extension.t

CHANGE DETAILS

diff --git a/tests/test-extension.t b/tests/test-extension.t
--- a/tests/test-extension.t
+++ b/tests/test-extension.t
@@ -2035,3 +2035,20 @@
   abort: failed to import extension "missing" from foo/bar/baz/I/do/not/exist/: [Errno 2] $ENOENT$: 'foo/bar/baz/I/do/not/exist'
   (loading of this extension was required, see `hg help config.extensions` for details)
   [255]
+
+Have a "default" setting for the suboption:
+
+  $ cat > $TESTTMP/mandatory-extensions/.hg/hgrc << EOF
+  > [extensions]
+  > bad = $TESTTMP/mandatory-extensions/.hg/bad.py
+  > bad:required = no
+  > good = $TESTTMP/mandatory-extensions/.hg/good.py
+  > syntax = $TESTTMP/mandatory-extensions/.hg/syntax.py
+  > *:required = yes
+  > EOF
+
+  $ hg -R mandatory-extensions id
+  *** failed to import extension "bad" from $TESTTMP/mandatory-extensions/.hg/bad.py: babar
+  abort: failed to import extension "syntax" from $TESTTMP/mandatory-extensions/.hg/syntax.py: invalid syntax (*syntax.py, line 1) (glob)
+  (loading of this extension was required, see `hg help config.extensions` for details)
+  [255]
diff --git a/tests/test-check-module-imports.t b/tests/test-check-module-imports.t
--- a/tests/test-check-module-imports.t
+++ b/tests/test-check-module-imports.t
@@ -41,4 +41,5 @@
   > -X tests/test-demandimport.py \
   > -X tests/test-imports-checker.t \
   > -X tests/test-verify-repo-operations.py \
+  > -X tests/test-extension.t \
   > | sed 's-\\-/-g' | "$PYTHON" "$import_checker" -
diff --git a/mercurial/helptext/config.txt b/mercurial/helptext/config.txt
--- a/mercurial/helptext/config.txt
+++ b/mercurial/helptext/config.txt
@@ -861,6 +861,13 @@
 To debug extension loading issue, one can add `--traceback` to their mercurial
 invocation.
 
+A default setting can we set using the special `*` extension key::
+
+  [extensions]
+  *:required = yes
+  myfeature = ~/.hgext/myfeature.py
+  rebase=
+
 
 ``format``
 ----------
diff --git a/mercurial/extensions.py b/mercurial/extensions.py
--- a/mercurial/extensions.py
+++ b/mercurial/extensions.py
@@ -291,6 +291,8 @@
     )
     ui.log(b'extension', b'- processing %d entries\n', len(result))
     with util.timedcm('load all extensions') as stats:
+        default_sub_options = ui.configsuboptions(b"extensions", b"*")[1]
+
         for (name, path) in result:
             if path:
                 if path[0:1] == b'!':
@@ -315,8 +317,10 @@
                     error_msg = _(b'failed to import extension "%s": %s')
                     error_msg %= (name, msg)
 
+                options = default_sub_options.copy()
                 ext_options = ui.configsuboptions(b"extensions", name)[1]
-                if stringutil.parsebool(ext_options.get(b"required", b'no')):
+                options.update(ext_options)
+                if stringutil.parsebool(options.get(b"required", b'no')):
                     hint = None
                     if isinstance(inst, error.Hint) and inst.hint:
                         hint = inst.hint



To: marmoute, #hg-reviewers, Alphare
Cc: mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20211130/0fa9c888/attachment-0002.html>


More information about the Mercurial-patches mailing list