##// END OF EJS Templates
configitems: handle case were the default value is not static...
Boris Feld -
r33471:d74141cc default
parent child Browse files
Show More
@@ -51,6 +51,9 b' def _register(configtable, *args, **kwar'
51 raise error.ProgrammingError(msg % (item.section, item.name))
51 raise error.ProgrammingError(msg % (item.section, item.name))
52 section[item.name] = item
52 section[item.name] = item
53
53
54 # special value for case where the default is derived from other values
55 dynamicdefault = object()
56
54 # Registering actual config items
57 # Registering actual config items
55
58
56 def getitemregister(configtable):
59 def getitemregister(configtable):
@@ -457,11 +457,17 b' class ui(object):'
457 if default is _unset:
457 if default is _unset:
458 if item is None:
458 if item is None:
459 value = default
459 value = default
460 elif item.default is configitems.dynamicdefault:
461 value = None
462 msg = "config item requires an explicit default value: '%s.%s'"
463 msg %= (section, name)
464 self.develwarn(msg, 2, 'warn-config-default')
460 elif callable(item.default):
465 elif callable(item.default):
461 value = item.default()
466 value = item.default()
462 else:
467 else:
463 value = item.default
468 value = item.default
464 elif item is not None:
469 elif (item is not None
470 and item.default is not configitems.dynamicdefault):
465 msg = ("specifying a default value for a registered "
471 msg = ("specifying a default value for a registered "
466 "config item: '%s.%s' '%s'")
472 "config item: '%s.%s' '%s'")
467 msg %= (section, name, default)
473 msg %= (section, name, default)
@@ -218,7 +218,7 b' Test warning on config option access and'
218 $ cat << EOF > ${TESTTMP}/buggyconfig.py
218 $ cat << EOF > ${TESTTMP}/buggyconfig.py
219 > """A small extension that tests our developer warnings for config"""
219 > """A small extension that tests our developer warnings for config"""
220 >
220 >
221 > from mercurial import registrar
221 > from mercurial import registrar, configitems
222 >
222 >
223 > cmdtable = {}
223 > cmdtable = {}
224 > command = registrar.command(cmdtable)
224 > command = registrar.command(cmdtable)
@@ -227,6 +227,7 b' Test warning on config option access and'
227 > configitem = registrar.configitem(configtable)
227 > configitem = registrar.configitem(configtable)
228 >
228 >
229 > configitem('test', 'some', default='foo')
229 > configitem('test', 'some', default='foo')
230 > configitem('test', 'dynamic', default=configitems.dynamicdefault)
230 > # overwrite a core config
231 > # overwrite a core config
231 > configitem('ui', 'quiet', default=False)
232 > configitem('ui', 'quiet', default=False)
232 > configitem('ui', 'interactive', default=None)
233 > configitem('ui', 'interactive', default=None)
@@ -236,6 +237,8 b' Test warning on config option access and'
236 > repo.ui.config('ui', 'quiet', False)
237 > repo.ui.config('ui', 'quiet', False)
237 > repo.ui.config('ui', 'interactive', None)
238 > repo.ui.config('ui', 'interactive', None)
238 > repo.ui.config('test', 'some', 'foo')
239 > repo.ui.config('test', 'some', 'foo')
240 > repo.ui.config('test', 'dynamic', 'some-required-default')
241 > repo.ui.config('test', 'dynamic')
239 > EOF
242 > EOF
240
243
241 $ hg --config "extensions.buggyconfig=${TESTTMP}/buggyconfig.py" buggyconfig
244 $ hg --config "extensions.buggyconfig=${TESTTMP}/buggyconfig.py" buggyconfig
@@ -244,5 +247,6 b' Test warning on config option access and'
244 devel-warn: specifying a default value for a registered config item: 'ui.quiet' 'False' at: $TESTTMP/buggyconfig.py:* (cmdbuggyconfig) (glob)
247 devel-warn: specifying a default value for a registered config item: 'ui.quiet' 'False' at: $TESTTMP/buggyconfig.py:* (cmdbuggyconfig) (glob)
245 devel-warn: specifying a default value for a registered config item: 'ui.interactive' 'None' at: $TESTTMP/buggyconfig.py:* (cmdbuggyconfig) (glob)
248 devel-warn: specifying a default value for a registered config item: 'ui.interactive' 'None' at: $TESTTMP/buggyconfig.py:* (cmdbuggyconfig) (glob)
246 devel-warn: specifying a default value for a registered config item: 'test.some' 'foo' at: $TESTTMP/buggyconfig.py:* (cmdbuggyconfig) (glob)
249 devel-warn: specifying a default value for a registered config item: 'test.some' 'foo' at: $TESTTMP/buggyconfig.py:* (cmdbuggyconfig) (glob)
250 devel-warn: config item requires an explicit default value: 'test.dynamic' at: $TESTTMP/buggyconfig.py:* (cmdbuggyconfig) (glob)
247
251
248 $ cd ..
252 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now