From patchwork Tue Jun 27 13:00:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [1, of, 6] configitems: extract the logic to build a registrar on any configtable From: Pierre-Yves David X-Patchwork-Id: 21774 Message-Id: <714ce79885e32305c45f.1498568430@nodosa.octopoid.net> To: mercurial-devel@mercurial-scm.org Date: Tue, 27 Jun 2017 15:00:30 +0200 # HG changeset patch # User Pierre-Yves David # Date 1497699533 -7200 # Sat Jun 17 13:38:53 2017 +0200 # Node ID 714ce79885e32305c45febf0da59b2ce2093967d # Parent eb4c49f55f1f0d7719f514c16bec54515eb54f62 # 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 714ce79885e3 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 @@ class configitem(object): 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 @@ def coreconfigitem(*args, **kwargs): # Registering actual config items +def getitemregister(configtable): + return functools.partial(_register, configtable) + +coreconfigitem = getitemregister(coreitems) + coreconfigitem('patch', 'fuzz', default=2, )