# HG changeset patch # User Pierre-Yves David # Date 2017-06-18 17:52:54 # Node ID bf1292c057ef9a740f7a5b126eb0cc9b0ebec7ce # Parent c467d13334ee0829f32933a85a8a7ed21a32d436 configitems: add a devel warning for extensions items overiding core one We do not want such case to pass silently. In the future we'll likely have useful tool for an extension to alter the existing definition in core. diff --git a/mercurial/configitems.py b/mercurial/configitems.py --- a/mercurial/configitems.py +++ b/mercurial/configitems.py @@ -16,7 +16,15 @@ from . import ( def loadconfigtable(ui, extname, configtable): """update config item known to the ui with the extension ones""" for section, items in configtable.items(): - ui._knownconfig.setdefault(section, {}).update(items) + knownitems = ui._knownconfig.setdefault(section, {}) + knownkeys = set(knownitems) + newkeys = set(items) + for key in sorted(knownkeys & newkeys): + msg = "extension '%s' overwrite config item '%s.%s'" + msg %= (extname, section, key) + ui.develwarn(msg, config='warn-config') + + knownitems.update(items) class configitem(object): """represent a known config item diff --git a/tests/test-devel-warnings.t b/tests/test-devel-warnings.t --- a/tests/test-devel-warnings.t +++ b/tests/test-devel-warnings.t @@ -203,14 +203,26 @@ Test warning on config option access and > cmdtable = {} > command = registrar.command(cmdtable) > + > configtable = {} + > configitem = registrar.configitem(configtable) + > + > configitem('test', 'some', default='foo') + > # overwrite a core config + > configitem('ui', 'quiet', default=False) + > configitem('ui', 'interactive', default=None) + > > @command(b'buggyconfig') > def cmdbuggyconfig(ui, repo): > repo.ui.config('ui', 'quiet', False) > repo.ui.config('ui', 'interactive', None) + > repo.ui.config('test', 'some', 'foo') > EOF $ hg --config "extensions.buggyconfig=${TESTTMP}/buggyconfig.py" buggyconfig + devel-warn: extension 'buggyconfig' overwrite config item 'ui.interactive' at: */mercurial/extensions.py:* (loadall) (glob) + devel-warn: extension 'buggyconfig' overwrite config item 'ui.quiet' at: */mercurial/extensions.py:* (loadall) (glob) devel-warn: specifying a default value for a registered config item: 'ui.quiet' 'False' at: $TESTTMP/buggyconfig.py:* (cmdbuggyconfig) (glob) devel-warn: specifying a default value for a registered config item: 'ui.interactive' 'None' at: $TESTTMP/buggyconfig.py:* (cmdbuggyconfig) (glob) + devel-warn: specifying a default value for a registered config item: 'test.some' 'foo' at: $TESTTMP/buggyconfig.py:* (cmdbuggyconfig) (glob) $ cd ..