# HG changeset patch # User Pierre-Yves David # Date 2017-06-17 11:08:03 # Node ID 149b68224b08a3b72701b177d118ba77fc09aa4f # Parent 2529e2ae9f4cfb49958fb9c5e5a95a39c9664f4c configitems: issue a devel warning when overriding default config If the option is registered, there is already a default value available and passing a new one is at best redundant. So we issue a deprecation warning in this case. (note: there will be case were the default value will not be as simple as what is currently possible. We'll upgrade the configitems code to handle them in time.) diff --git a/mercurial/ui.py b/mercurial/ui.py --- a/mercurial/ui.py +++ b/mercurial/ui.py @@ -445,11 +445,17 @@ class ui(object): if default is _unset: default = None else: + item = self._knownconfig.get(section, {}).get(name) if default is _unset: default = None - item = self._knownconfig.get(section, {}).get(name) if item is not None: default = item.default + elif item is not None: + msg = ("specifying a default value for a registered " + "config item: '%s.%s' '%s'") + msg %= (section, name, default) + self.develwarn(msg, 1, 'warn-config-default') + alternates = [name] for n in alternates: 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 @@ -193,4 +193,23 @@ Old style deprecation warning $ HGEMITWARNINGS= hg nouiwarning +Test warning on config option access and registration + + $ cat << EOF > ${TESTTMP}/buggyconfig.py + > """A small extension that tests our developer warnings for config""" + > + > from mercurial import registrar + > + > cmdtable = {} + > command = registrar.command(cmdtable) + > + > @command('buggyconfig') + > def cmdbuggyconfig(ui, repo): + > repo.ui.config('ui', 'quiet', False) + > repo.ui.config('ui', 'interactive', None) + > EOF + + $ hg --config "extensions.buggyconfig=${TESTTMP}/buggyconfig.py" buggyconfig + devel-warn: specifying a default value for a registered config item: 'ui.quiet' 'False' at: $TESTTMP/buggyconfig.py:* (cmdbuggyconfig) (glob) + $ cd ..