changeset 33002:6d983e8af49c

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.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sat, 17 Jun 2017 18:43:27 +0200
parents 0d757af1ea67
children 28a65fd4b359
files mercurial/configitems.py mercurial/ui.py
diffstat 2 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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