changeset 33133:bf1292c057ef

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.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sun, 18 Jun 2017 19:52:54 +0200
parents c467d13334ee
children 7dc090faa8a4
files mercurial/configitems.py tests/test-devel-warnings.t
diffstat 2 files changed, 21 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/configitems.py	Sat Jun 17 13:48:20 2017 +0200
+++ b/mercurial/configitems.py	Sun Jun 18 19:52:54 2017 +0200
@@ -16,7 +16,15 @@
 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
--- a/tests/test-devel-warnings.t	Sat Jun 17 13:48:20 2017 +0200
+++ b/tests/test-devel-warnings.t	Sun Jun 18 19:52:54 2017 +0200
@@ -203,14 +203,26 @@
   > 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 ..