[PATCH 3 of 6] configitems: add a devel warning for extensions items overiding core one

Pierre-Yves David pierre-yves.david at ens-lyon.org
Thu Jun 22 03:34:32 EDT 2017


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at octobus.net>
# Date 1497808374 -7200
#      Sun Jun 18 19:52:54 2017 +0200
# Node ID f69b5b8655172cc33f0765809c9c7620978910c0
# Parent  630aa32cf23b88fa9ab2d7ffac94ecea1307b4c0
# EXP-Topic config.register
# Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
#              hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r f69b5b865517
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('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/dispatch.py:* (_dispatch) (glob)
+  devel-warn: extension 'buggyconfig' overwrite config item 'ui.quiet' at: */mercurial/dispatch.py:* (_dispatch) (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 ..


More information about the Mercurial-devel mailing list