configitems: introduce a central registry for config option
authorPierre-Yves David <pierre-yves.david@octobus.net>
Sat, 17 Jun 2017 18:43:27 +0200
changeset 32984 6d983e8af49c
parent 32983 0d757af1ea67
child 32985 28a65fd4b359
configitems: introduce a central registry for config option We now have the appropriate infrastructure to register config items. Usage will added in the next changeset.
mercurial/configitems.py
mercurial/ui.py
--- a/mercurial/configitems.py	Sat Jun 17 18:41:55 2017 +0200
+++ b/mercurial/configitems.py	Sat Jun 17 18:43:27 2017 +0200
@@ -7,6 +7,10 @@
 
 from __future__ import absolute_import
 
+from . import (
+    error,
+)
+
 class configitem(object):
     """represent a known config item
 
@@ -19,3 +23,13 @@
         self.section = section
         self.name = name
         self.default = default
+
+coreitems = {}
+
+def coreconfigitem(*args, **kwargs):
+    item = configitem(*args, **kwargs)
+    section = coreitems.setdefault(item.section, {})
+    if item.name in section:
+        msg = "duplicated config item registration for '%s.%s'"
+        raise error.ProgrammingError(msg % (item.section, item.name))
+    section[item.name] = item
--- a/mercurial/ui.py	Sat Jun 17 18:41:55 2017 +0200
+++ b/mercurial/ui.py	Sat Jun 17 18:43:27 2017 +0200
@@ -27,6 +27,7 @@
 from . import (
     color,
     config,
+    configitems,
     encoding,
     error,
     formatter,
@@ -178,6 +179,7 @@
         self._bufferapplylabels = None
         self.quiet = self.verbose = self.debugflag = self.tracebackflag = False
         self._reportuntrusted = True
+        self._knownconfig = configitems.coreitems
         self._ocfg = config.config() # overlay
         self._tcfg = config.config() # trusted
         self._ucfg = config.config() # untrusted