Patchwork [1,of,6] configitems: extract the logic to build a registrar on any configtable

login
register
mail settings
Submitter Pierre-Yves David
Date June 27, 2017, 1 p.m.
Message ID <714ce79885e32305c45f.1498568430@nodosa.octopoid.net>
Download mbox | patch
Permalink /patch/21774/
State Accepted
Headers show

Comments

Pierre-Yves David - June 27, 2017, 1 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@octobus.net>
# 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.
Yuya Nishihara - June 29, 2017, 1:43 p.m.
On Tue, 27 Jun 2017 15:00:30 +0200, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@octobus.net>
> # 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

Queued these, thanks.

Patch

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