Show More
@@ -51,6 +51,9 b' def _register(configtable, *args, **kwar' | |||
|
51 | 51 | raise error.ProgrammingError(msg % (item.section, item.name)) |
|
52 | 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 | 57 | # Registering actual config items |
|
55 | 58 | |
|
56 | 59 | def getitemregister(configtable): |
@@ -457,11 +457,17 b' class ui(object):' | |||
|
457 | 457 | if default is _unset: |
|
458 | 458 | if item is None: |
|
459 | 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 | 465 | elif callable(item.default): |
|
461 | 466 | value = item.default() |
|
462 | 467 | else: |
|
463 | 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 | 471 | msg = ("specifying a default value for a registered " |
|
466 | 472 | "config item: '%s.%s' '%s'") |
|
467 | 473 | msg %= (section, name, default) |
@@ -218,7 +218,7 b' Test warning on config option access and' | |||
|
218 | 218 | $ cat << EOF > ${TESTTMP}/buggyconfig.py |
|
219 | 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 | 223 | > cmdtable = {} |
|
224 | 224 | > command = registrar.command(cmdtable) |
@@ -227,6 +227,7 b' Test warning on config option access and' | |||
|
227 | 227 | > configitem = registrar.configitem(configtable) |
|
228 | 228 | > |
|
229 | 229 | > configitem('test', 'some', default='foo') |
|
230 | > configitem('test', 'dynamic', default=configitems.dynamicdefault) | |
|
230 | 231 | > # overwrite a core config |
|
231 | 232 | > configitem('ui', 'quiet', default=False) |
|
232 | 233 | > configitem('ui', 'interactive', default=None) |
@@ -236,6 +237,8 b' Test warning on config option access and' | |||
|
236 | 237 | > repo.ui.config('ui', 'quiet', False) |
|
237 | 238 | > repo.ui.config('ui', 'interactive', None) |
|
238 | 239 | > repo.ui.config('test', 'some', 'foo') |
|
240 | > repo.ui.config('test', 'dynamic', 'some-required-default') | |
|
241 | > repo.ui.config('test', 'dynamic') | |
|
239 | 242 | > EOF |
|
240 | 243 | |
|
241 | 244 | $ hg --config "extensions.buggyconfig=${TESTTMP}/buggyconfig.py" buggyconfig |
@@ -244,5 +247,6 b' Test warning on config option access and' | |||
|
244 | 247 | devel-warn: specifying a default value for a registered config item: 'ui.quiet' 'False' at: $TESTTMP/buggyconfig.py:* (cmdbuggyconfig) (glob) |
|
245 | 248 | devel-warn: specifying a default value for a registered config item: 'ui.interactive' 'None' at: $TESTTMP/buggyconfig.py:* (cmdbuggyconfig) (glob) |
|
246 | 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 | 252 | $ cd .. |
General Comments 0
You need to be logged in to leave comments.
Login now