comparison mercurial/configitems.py @ 33131:c2ca511c4771

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.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Sat, 17 Jun 2017 13:38:53 +0200
parents c41cbe98822c
children c467d13334ee
comparison
equal deleted inserted replaced
33130:31ab1912678a 33131:c2ca511c4771
4 # 4 #
5 # This software may be used and distributed according to the terms of the 5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version. 6 # GNU General Public License version 2 or any later version.
7 7
8 from __future__ import absolute_import 8 from __future__ import absolute_import
9
10 import functools
9 11
10 from . import ( 12 from . import (
11 error, 13 error,
12 ) 14 )
13 15
24 self.name = name 26 self.name = name
25 self.default = default 27 self.default = default
26 28
27 coreitems = {} 29 coreitems = {}
28 30
29 def coreconfigitem(*args, **kwargs): 31 def _register(configtable, *args, **kwargs):
30 item = configitem(*args, **kwargs) 32 item = configitem(*args, **kwargs)
31 section = coreitems.setdefault(item.section, {}) 33 section = configtable.setdefault(item.section, {})
32 if item.name in section: 34 if item.name in section:
33 msg = "duplicated config item registration for '%s.%s'" 35 msg = "duplicated config item registration for '%s.%s'"
34 raise error.ProgrammingError(msg % (item.section, item.name)) 36 raise error.ProgrammingError(msg % (item.section, item.name))
35 section[item.name] = item 37 section[item.name] = item
36 38
37 # Registering actual config items 39 # Registering actual config items
40
41 def getitemregister(configtable):
42 return functools.partial(_register, configtable)
43
44 coreconfigitem = getitemregister(coreitems)
38 45
39 coreconfigitem('patch', 'fuzz', 46 coreconfigitem('patch', 'fuzz',
40 default=2, 47 default=2,
41 ) 48 )
42 coreconfigitem('ui', 'clonebundleprefers', 49 coreconfigitem('ui', 'clonebundleprefers',