configitems: extract the logic to build a registrar on any configtable
authorPierre-Yves David <pierre-yves.david@octobus.net>
Sat, 17 Jun 2017 13:38:53 +0200
changeset 33131 c2ca511c4771
parent 33130 31ab1912678a
child 33132 c467d13334ee
configitems: extract the logic to build a registrar on any configtable Having the logic available independently from the mapping used is a necessary step toward extensions support.
mercurial/configitems.py
--- a/mercurial/configitems.py	Mon Jun 19 01:08:11 2017 +0200
+++ b/mercurial/configitems.py	Sat Jun 17 13:38:53 2017 +0200
@@ -7,6 +7,8 @@
 
 from __future__ import absolute_import
 
+import functools
+
 from . import (
     error,
 )
@@ -26,9 +28,9 @@
 
 coreitems = {}
 
-def coreconfigitem(*args, **kwargs):
+def _register(configtable, *args, **kwargs):
     item = configitem(*args, **kwargs)
-    section = coreitems.setdefault(item.section, {})
+    section = configtable.setdefault(item.section, {})
     if item.name in section:
         msg = "duplicated config item registration for '%s.%s'"
         raise error.ProgrammingError(msg % (item.section, item.name))
@@ -36,6 +38,11 @@
 
 # Registering actual config items
 
+def getitemregister(configtable):
+    return functools.partial(_register, configtable)
+
+coreconfigitem = getitemregister(coreitems)
+
 coreconfigitem('patch', 'fuzz',
     default=2,
 )