Patchwork [2,of,8] configitems: introduce a central registry for config option

login
register
mail settings
Submitter Pierre-Yves David
Date June 21, 2017, 8:55 a.m.
Message ID <8610aec63456a82a48a0.1498035303@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/21592/
State Accepted
Headers show

Comments

Pierre-Yves David - June 21, 2017, 8:55 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1497717807 -7200
#      Sat Jun 17 18:43:27 2017 +0200
# Node ID 8610aec63456a82a48a050fb73f1d80d1e49bcc1
# Parent  76b9e5749847f4c80a9bbd70f1eede96cb41e4fe
# 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 8610aec63456
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.

Patch

diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -23,3 +23,13 @@  class configitem(object):
         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
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -27,6 +27,7 @@  from .node import hex
 from . import (
     color,
     config,
+    configitems,
     encoding,
     error,
     formatter,
@@ -178,6 +179,7 @@  class ui(object):
         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