Show More
@@ -471,12 +471,16 b' class ui(object):' | |||||
471 | return value |
|
471 | return value | |
472 |
|
472 | |||
473 | def _config(self, section, name, default=_unset, untrusted=False): |
|
473 | def _config(self, section, name, default=_unset, untrusted=False): | |
474 | value = default |
|
474 | value = itemdefault = default | |
475 | item = self._knownconfig.get(section, {}).get(name) |
|
475 | item = self._knownconfig.get(section, {}).get(name) | |
476 | alternates = [(section, name)] |
|
476 | alternates = [(section, name)] | |
477 |
|
477 | |||
478 | if item is not None: |
|
478 | if item is not None: | |
479 | alternates.extend(item.alias) |
|
479 | alternates.extend(item.alias) | |
|
480 | if callable(item.default): | |||
|
481 | itemdefault = item.default() | |||
|
482 | else: | |||
|
483 | itemdefault = item.default | |||
480 | else: |
|
484 | else: | |
481 | msg = ("accessing unregistered config item: '%s.%s'") |
|
485 | msg = ("accessing unregistered config item: '%s.%s'") | |
482 | msg %= (section, name) |
|
486 | msg %= (section, name) | |
@@ -490,13 +494,12 b' class ui(object):' | |||||
490 | msg = "config item requires an explicit default value: '%s.%s'" |
|
494 | msg = "config item requires an explicit default value: '%s.%s'" | |
491 | msg %= (section, name) |
|
495 | msg %= (section, name) | |
492 | self.develwarn(msg, 2, 'warn-config-default') |
|
496 | self.develwarn(msg, 2, 'warn-config-default') | |
493 | elif callable(item.default): |
|
|||
494 | value = item.default() |
|
|||
495 | else: |
|
497 | else: | |
496 |
value = item |
|
498 | value = itemdefault | |
497 | elif (item is not None |
|
499 | elif (item is not None | |
498 |
and item.default is not configitems.dynamicdefault |
|
500 | and item.default is not configitems.dynamicdefault | |
499 | msg = ("specifying a default value for a registered " |
|
501 | and default != itemdefault): | |
|
502 | msg = ("specifying a mismatched default value for a registered " | |||
500 | "config item: '%s.%s' '%s'") |
|
503 | "config item: '%s.%s' '%s'") | |
501 | msg %= (section, name, default) |
|
504 | msg %= (section, name, default) | |
502 | self.develwarn(msg, 2, 'warn-config-default') |
|
505 | self.develwarn(msg, 2, 'warn-config-default') |
@@ -352,17 +352,21 b' Test warning on config option access and' | |||||
352 | > |
|
352 | > | |
353 | > configitem('test', 'some', default='foo') |
|
353 | > configitem('test', 'some', default='foo') | |
354 | > configitem('test', 'dynamic', default=configitems.dynamicdefault) |
|
354 | > configitem('test', 'dynamic', default=configitems.dynamicdefault) | |
|
355 | > configitem('test', 'callable', default=list) | |||
355 | > # overwrite a core config |
|
356 | > # overwrite a core config | |
356 | > configitem('ui', 'quiet', default=False) |
|
357 | > configitem('ui', 'quiet', default=False) | |
357 | > configitem('ui', 'interactive', default=None) |
|
358 | > configitem('ui', 'interactive', default=None) | |
358 | > |
|
359 | > | |
359 | > @command(b'buggyconfig') |
|
360 | > @command(b'buggyconfig') | |
360 | > def cmdbuggyconfig(ui, repo): |
|
361 | > def cmdbuggyconfig(ui, repo): | |
361 |
> repo.ui.config('ui', 'quiet', |
|
362 | > repo.ui.config('ui', 'quiet', True) | |
362 |
> repo.ui.config('ui', 'interactive', |
|
363 | > repo.ui.config('ui', 'interactive', False) | |
|
364 | > repo.ui.config('test', 'some', 'bar') | |||
363 | > repo.ui.config('test', 'some', 'foo') |
|
365 | > repo.ui.config('test', 'some', 'foo') | |
364 | > repo.ui.config('test', 'dynamic', 'some-required-default') |
|
366 | > repo.ui.config('test', 'dynamic', 'some-required-default') | |
365 | > repo.ui.config('test', 'dynamic') |
|
367 | > repo.ui.config('test', 'dynamic') | |
|
368 | > repo.ui.config('test', 'callable', []) | |||
|
369 | > repo.ui.config('test', 'callable', 'foo') | |||
366 | > repo.ui.config('test', 'unregistered') |
|
370 | > repo.ui.config('test', 'unregistered') | |
367 | > repo.ui.config('unregistered', 'unregistered') |
|
371 | > repo.ui.config('unregistered', 'unregistered') | |
368 | > EOF |
|
372 | > EOF | |
@@ -370,10 +374,11 b' Test warning on config option access and' | |||||
370 | $ hg --config "extensions.buggyconfig=${TESTTMP}/buggyconfig.py" buggyconfig |
|
374 | $ hg --config "extensions.buggyconfig=${TESTTMP}/buggyconfig.py" buggyconfig | |
371 | devel-warn: extension 'buggyconfig' overwrite config item 'ui.interactive' at: */mercurial/extensions.py:* (_loadextra) (glob) |
|
375 | devel-warn: extension 'buggyconfig' overwrite config item 'ui.interactive' at: */mercurial/extensions.py:* (_loadextra) (glob) | |
372 | devel-warn: extension 'buggyconfig' overwrite config item 'ui.quiet' at: */mercurial/extensions.py:* (_loadextra) (glob) |
|
376 | devel-warn: extension 'buggyconfig' overwrite config item 'ui.quiet' at: */mercurial/extensions.py:* (_loadextra) (glob) | |
373 |
devel-warn: specifying a default value for a registered config item: 'ui.quiet' ' |
|
377 | devel-warn: specifying a mismatched default value for a registered config item: 'ui.quiet' 'True' at: $TESTTMP/buggyconfig.py:* (cmdbuggyconfig) (glob) | |
374 |
devel-warn: specifying a default value for a registered config item: 'ui.interactive' ' |
|
378 | devel-warn: specifying a mismatched default value for a registered config item: 'ui.interactive' 'False' at: $TESTTMP/buggyconfig.py:* (cmdbuggyconfig) (glob) | |
375 |
devel-warn: specifying a default value for a registered config item: 'test.some' ' |
|
379 | devel-warn: specifying a mismatched default value for a registered config item: 'test.some' 'bar' at: $TESTTMP/buggyconfig.py:* (cmdbuggyconfig) (glob) | |
376 | devel-warn: config item requires an explicit default value: 'test.dynamic' at: $TESTTMP/buggyconfig.py:* (cmdbuggyconfig) (glob) |
|
380 | devel-warn: config item requires an explicit default value: 'test.dynamic' at: $TESTTMP/buggyconfig.py:* (cmdbuggyconfig) (glob) | |
|
381 | devel-warn: specifying a mismatched default value for a registered config item: 'test.callable' 'foo' at: $TESTTMP/buggyconfig.py:* (cmdbuggyconfig) (glob) | |||
377 | devel-warn: accessing unregistered config item: 'test.unregistered' at: $TESTTMP/buggyconfig.py:* (cmdbuggyconfig) (glob) |
|
382 | devel-warn: accessing unregistered config item: 'test.unregistered' at: $TESTTMP/buggyconfig.py:* (cmdbuggyconfig) (glob) | |
378 | devel-warn: accessing unregistered config item: 'unregistered.unregistered' at: $TESTTMP/buggyconfig.py:* (cmdbuggyconfig) (glob) |
|
383 | devel-warn: accessing unregistered config item: 'unregistered.unregistered' at: $TESTTMP/buggyconfig.py:* (cmdbuggyconfig) (glob) | |
379 |
|
384 |
General Comments 0
You need to be logged in to leave comments.
Login now