# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# Date 1497699533 -7200
# Node ID c2ca511c4771e6dfdb660f0eb62fbe98bbec187e
# Parent  31ab1912678a8262ff57414c57c08dd1ce248ce8
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.

diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -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,
 )