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.
--- 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,
)