[PATCH 1 of 6] configitems: extract the logic to build a registrar on any configtable
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Thu Jun 22 07:34:30 UTC 2017
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at octobus.net>
# Date 1497699533 -7200
# Sat Jun 17 13:38:53 2017 +0200
# Node ID 1b9be14a52e0789ffbaae58252f0b753fe213f86
# Parent 698542a0f8e8e7270661fbe20d53085d967f5305
# 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 1b9be14a52e0
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,
)
More information about the Mercurial-devel
mailing list