Rev 6094: Update registered option default values and also convert the default value if the first conversion fails. in file:///home/vila/src/bzr/experimental/convert-default-values/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Mon Aug 22 14:15:36 UTC 2011
At file:///home/vila/src/bzr/experimental/convert-default-values/
------------------------------------------------------------
revno: 6094
revision-id: v.ladeuil+lp at free.fr-20110822141536-70v01odqnwyc08qt
parent: v.ladeuil+lp at free.fr-20110822133119-fyp1purjip5pu3uy
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: convert-default-values
timestamp: Mon 2011-08-22 16:15:36 +0200
message:
Update registered option default values and also convert the default value if the first conversion fails.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2011-08-22 13:31:19 +0000
+++ b/bzrlib/config.py 2011-08-22 14:15:36 +0000
@@ -2322,7 +2322,7 @@
:param name: the name used to refer to the option.
:param default: the default value to use when none exist in the config
- stores.
+ stores. This must be a string as it appears in the config stores.
:param default_from_env: A list of environment variables which can
provide a default value. 'default' will be used only if none of the
@@ -2354,7 +2354,7 @@
def convert_from_unicode(self, unicode_value):
if self.from_unicode is None or unicode_value is None:
- # Cannot convert
+ # Don't convert or nothing to convert
return unicode_value
try:
converted = self.from_unicode(unicode_value)
@@ -2457,7 +2457,7 @@
# Registered options in lexicographical order
option_registry.register(
- Option('bzr.workingtree.worth_saving_limit', default=10,
+ Option('bzr.workingtree.worth_saving_limit', default='10',
from_unicode=int_from_store, invalid='warning',
help='''\
How many changes before saving the dirstate.
@@ -2469,7 +2469,7 @@
a file has been touched.
'''))
option_registry.register(
- Option('dirstate.fdatasync', default=True,
+ Option('dirstate.fdatasync', default='True',
from_unicode=bool_from_store,
help='''\
Flush dirstate changes onto physical disk?
@@ -2479,7 +2479,7 @@
should not be lost if the machine crashes. See also repository.fdatasync.
'''))
option_registry.register(
- Option('debug_flags', default=[], from_unicode=list_from_store,
+ Option('debug_flags', default='', from_unicode=list_from_store,
help='Debug flags to activate.'))
option_registry.register(
Option('default_format', default='2a',
@@ -2488,7 +2488,7 @@
Option('editor',
help='The command called to launch an editor to enter a message.'))
option_registry.register(
- Option('ignore_missing_extensions', default=False,
+ Option('ignore_missing_extensions', default='False',
from_unicode=bool_from_store,
help='''\
Control the missing extensions warning display.
@@ -2499,7 +2499,7 @@
Option('language',
help='Language to translate messages into.'))
option_registry.register(
- Option('locks.steal_dead', default=False, from_unicode=bool_from_store,
+ Option('locks.steal_dead', default='False', from_unicode=bool_from_store,
help='''\
Steal locks that appears to be dead.
@@ -2515,7 +2515,7 @@
help= 'Unicode encoding for output'
' (terminal encoding if not specified).'))
option_registry.register(
- Option('repository.fdatasync', default=True, from_unicode=bool_from_store,
+ Option('repository.fdatasync', default='True', from_unicode=bool_from_store,
help='''\
Flush repository changes onto physical disk?
@@ -2987,11 +2987,12 @@
except KeyError:
# Not registered
opt = None
- if value is None and opt is not None:
- # If the option is registered, it may provide a default value
- value = opt.get_default()
if opt is not None:
value = opt.convert_from_unicode(value)
+ if value is None:
+ # The conversion failed or there was no value to convert,
+ # fallback to the default value
+ value = opt.convert_from_unicode(opt.get_default())
for hook in ConfigHooks['get']:
hook(self, name, value)
return value
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py 2011-08-22 13:31:19 +0000
+++ b/bzrlib/tests/test_config.py 2011-08-22 14:15:36 +0000
@@ -3139,11 +3139,16 @@
self.register_bool_option('foo', u'False')
self.assertEquals(False, self.conf.get('foo'))
- def test_get_default_from_env_converted(self):
+ def test_get_default_bool_from_env_converted(self):
self.register_bool_option('foo', u'True', default_from_env=['FOO'])
self.overrideEnv('FOO', 'False')
self.assertEquals(False, self.conf.get('foo'))
+ def test_get_default_bool_when_conversion_fails(self):
+ self.register_bool_option('foo', default='True')
+ self.conf.store._load_from_string('foo=invalid boolean')
+ self.assertEquals(True, self.conf.get('foo'))
+
def register_integer_option(self, name,
default=None, default_from_env=None):
i = config.Option(name, help='An integer.',
@@ -3164,6 +3169,11 @@
self.overrideEnv('FOO', '18')
self.assertEquals(18, self.conf.get('foo'))
+ def test_get_default_integer_when_conversion_fails(self):
+ self.register_integer_option('foo', default='12')
+ self.conf.store._load_from_string('foo=invalid integer')
+ self.assertEquals(12, self.conf.get('foo'))
+
def register_list_option(self, name, default=None, default_from_env=None):
l = config.Option(name, help='A list.',
default=default, default_from_env=default_from_env,
More information about the bazaar-commits
mailing list