This is similar to what we do in other section (e.g. paths) and allow to
change the behavior for all extensions.
Sub options on individual extensions overwrite the default settings.
Alphare |
hg-reviewers |
This is similar to what we do in other section (e.g. paths) and allow to
change the behavior for all extensions.
Sub options on individual extensions overwrite the default settings.
No Linters Available |
No Unit Test Coverage |
Path | Packages | |||
---|---|---|---|---|
M | mercurial/extensions.py (6 lines) | |||
M | mercurial/helptext/config.txt (7 lines) | |||
M | tests/test-check-module-imports.t (1 line) | |||
M | tests/test-extension.t (17 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
94b91fa5c0c2 | 337ee46ccd69 | Pierre-Yves David | Nov 26 2021, 11:22 AM |
newindex = len(_order) | newindex = len(_order) | ||||
ui.log( | ui.log( | ||||
b'extension', | b'extension', | ||||
b'loading %sextensions\n', | b'loading %sextensions\n', | ||||
b'additional ' if newindex else b'', | b'additional ' if newindex else b'', | ||||
) | ) | ||||
ui.log(b'extension', b'- processing %d entries\n', len(result)) | ui.log(b'extension', b'- processing %d entries\n', len(result)) | ||||
with util.timedcm('load all extensions') as stats: | with util.timedcm('load all extensions') as stats: | ||||
default_sub_options = ui.configsuboptions(b"extensions", b"*")[1] | |||||
for (name, path) in result: | for (name, path) in result: | ||||
if path: | if path: | ||||
if path[0:1] == b'!': | if path[0:1] == b'!': | ||||
if name not in _disabledextensions: | if name not in _disabledextensions: | ||||
ui.log( | ui.log( | ||||
b'extension', | b'extension', | ||||
b' - skipping disabled extension: %s\n', | b' - skipping disabled extension: %s\n', | ||||
name, | name, | ||||
) | ) | ||||
_disabledextensions[name] = path[1:] | _disabledextensions[name] = path[1:] | ||||
continue | continue | ||||
try: | try: | ||||
load(ui, name, path, loadingtime) | load(ui, name, path, loadingtime) | ||||
except Exception as inst: | except Exception as inst: | ||||
msg = stringutil.forcebytestr(inst) | msg = stringutil.forcebytestr(inst) | ||||
if path: | if path: | ||||
error_msg = _( | error_msg = _( | ||||
b'failed to import extension "%s" from %s: %s' | b'failed to import extension "%s" from %s: %s' | ||||
) | ) | ||||
error_msg %= (name, path, msg) | error_msg %= (name, path, msg) | ||||
else: | else: | ||||
error_msg = _(b'failed to import extension "%s": %s') | error_msg = _(b'failed to import extension "%s": %s') | ||||
error_msg %= (name, msg) | error_msg %= (name, msg) | ||||
options = default_sub_options.copy() | |||||
ext_options = ui.configsuboptions(b"extensions", name)[1] | 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 | hint = None | ||||
if isinstance(inst, error.Hint) and inst.hint: | if isinstance(inst, error.Hint) and inst.hint: | ||||
hint = inst.hint | hint = inst.hint | ||||
if hint is None: | if hint is None: | ||||
hint = _( | hint = _( | ||||
b"loading of this extension was required, " | b"loading of this extension was required, " | ||||
b"see `hg help config.extensions` for details" | b"see `hg help config.extensions` for details" | ||||
) | ) |
[extensions] | [extensions] | ||||
myfeature = ~/.hgext/myfeature.py | myfeature = ~/.hgext/myfeature.py | ||||
myfeature:required = yes | myfeature:required = yes | ||||
To debug extension loading issue, one can add `--traceback` to their mercurial | To debug extension loading issue, one can add `--traceback` to their mercurial | ||||
invocation. | invocation. | ||||
A default setting can we set using the special `*` extension key:: | |||||
[extensions] | |||||
*:required = yes | |||||
myfeature = ~/.hgext/myfeature.py | |||||
rebase= | |||||
``format`` | ``format`` | ||||
---------- | ---------- | ||||
Configuration that controls the repository format. Newer format options are more | Configuration that controls the repository format. Newer format options are more | ||||
powerful, but incompatible with some older versions of Mercurial. Format options | powerful, but incompatible with some older versions of Mercurial. Format options | ||||
are considered at repository initialization only. You need to make a new clone | are considered at repository initialization only. You need to make a new clone | ||||
for config changes to be taken into account. | for config changes to be taken into account. |
> -X doc/hgmanpage.py \ | > -X doc/hgmanpage.py \ | ||||
> -X i18n/posplit \ | > -X i18n/posplit \ | ||||
> -X mercurial/thirdparty \ | > -X mercurial/thirdparty \ | ||||
> -X tests/hypothesishelpers.py \ | > -X tests/hypothesishelpers.py \ | ||||
> -X tests/test-check-interfaces.py \ | > -X tests/test-check-interfaces.py \ | ||||
> -X tests/test-demandimport.py \ | > -X tests/test-demandimport.py \ | ||||
> -X tests/test-imports-checker.t \ | > -X tests/test-imports-checker.t \ | ||||
> -X tests/test-verify-repo-operations.py \ | > -X tests/test-verify-repo-operations.py \ | ||||
> -X tests/test-extension.t \ | |||||
> | sed 's-\\-/-g' | "$PYTHON" "$import_checker" - | > | sed 's-\\-/-g' | "$PYTHON" "$import_checker" - |
> missing = foo/bar/baz/I/do/not/exist/ | > missing = foo/bar/baz/I/do/not/exist/ | ||||
> missing:required = yes | > missing:required = yes | ||||
> EOF | > EOF | ||||
$ hg -R mandatory-extensions id | $ hg -R mandatory-extensions id | ||||
abort: failed to import extension "missing" from foo/bar/baz/I/do/not/exist/: [Errno 2] $ENOENT$: 'foo/bar/baz/I/do/not/exist' | 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) | (loading of this extension was required, see `hg help config.extensions` for details) | ||||
[255] | [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] |