Merge lp:~vila/bzr/824513-fadatasync-options into lp:bzr/2.4

Proposed by Vincent Ladeuil
Status: Merged
Approved by: Vincent Ladeuil
Approved revision: no longer in the source branch.
Merged at revision: 6039
Proposed branch: lp:~vila/bzr/824513-fadatasync-options
Merge into: lp:bzr/2.4
Diff against target: 162 lines (+76/-15)
3 files modified
bzrlib/config.py (+29/-8)
bzrlib/tests/test_config.py (+44/-7)
doc/en/release-notes/bzr-2.4.txt (+3/-0)
To merge this branch: bzr merge lp:~vila/bzr/824513-fadatasync-options
Reviewer Review Type Date Requested Status
Martin Pool Approve
Review via email: mp+72454@code.launchpad.net

Commit message

Properly handle boolean options.

Description of the change

This allows repository.fdatasync and dirstate.fdatasync to be
disabled by setting them to any valid boolean value in the config
files.

Great care will be needed when merging upstream as I
cherry-picked *part* of the initial boolean option implementation.

To post a comment you must log in.
Revision history for this message
Martin Pool (mbp) wrote :

> This allows repository.fdatasync and dirstate.fdatasync to be disabled by setting them to any valid boolean value in the config files.

I assume you mean setting them to any valid equivalent of 'false'?

The patch looks ok.

review: Approve
Revision history for this message
Vincent Ladeuil (vila) wrote :

> I assume you mean setting them to any valid equivalent of 'false'?

Right, any boolean value can be used but disabling is only achieved for 'false' values of course.

Revision history for this message
Vincent Ladeuil (vila) wrote :

sent to pqm by email

Revision history for this message
Vincent Ladeuil (vila) wrote :

sent to pqm by email

Revision history for this message
John A Meinel (jameinel) wrote :

sent to pqm by email

Revision history for this message
Vincent Ladeuil (vila) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/config.py'
2--- bzrlib/config.py 2011-08-19 08:12:12 +0000
3+++ bzrlib/config.py 2011-08-24 08:04:25 +0000
4@@ -2264,14 +2264,21 @@
5 value, in which config files it can be stored, etc (TBC).
6 """
7
8- def __init__(self, name, default=None):
9+ def __init__(self, name, default=None, from_unicode=None):
10 self.name = name
11 self.default = default
12+ self.from_unicode = from_unicode
13
14 def get_default(self):
15 return self.default
16
17
18+# Predefined converters to get proper values from store
19+
20+def bool_from_store(unicode_str):
21+ return ui.bool_from_string(unicode_str)
22+
23+
24 # Options registry
25
26 option_registry = registry.Registry()
27@@ -2282,12 +2289,13 @@
28 help='The command called to launch an editor to enter a message.')
29
30 option_registry.register(
31- 'dirstate.fdatasync', Option('dirstate.fdatasync', default=True),
32+ 'dirstate.fdatasync', Option('dirstate.fdatasync', default=True,
33+ from_unicode=bool_from_store),
34 help='Flush dirstate changes onto physical disk?')
35
36 option_registry.register(
37 'repository.fdatasync',
38- Option('repository.fdatasync', default=True),
39+ Option('repository.fdatasync', default=True, from_unicode=bool_from_store),
40 help='Flush repository changes onto physical disk?')
41
42
43@@ -2746,15 +2754,28 @@
44 break
45 if value is not None:
46 break
47+ # If the option is registered, it may provide additional info about
48+ # value handling
49+ try:
50+ opt = option_registry.get(name)
51+ except KeyError:
52+ # Not registered
53+ opt = None
54+ if (opt is not None and opt.from_unicode is not None
55+ and value is not None):
56+ # If a value exists and the option provides a converter, use it
57+ try:
58+ converted = opt.from_unicode(value)
59+ except (ValueError, TypeError):
60+ # Invalid values are ignored
61+ converted = None
62+ value = converted
63 if value is None:
64 # If the option is registered, it may provide a default value
65- try:
66- opt = option_registry.get(name)
67- except KeyError:
68- # Not registered
69- opt = None
70 if opt is not None:
71 value = opt.get_default()
72+ if opt is not None and value is None:
73+ value = opt.get_default()
74 for hook in ConfigHooks['get']:
75 hook(self, name, value)
76 return value
77
78=== modified file 'bzrlib/tests/test_config.py'
79--- bzrlib/tests/test_config.py 2011-08-19 08:12:12 +0000
80+++ bzrlib/tests/test_config.py 2011-08-24 08:04:25 +0000
81@@ -2940,23 +2940,60 @@
82
83 class TestStackGet(TestStackWithTransport):
84
85+ def setUp(self):
86+ super(TestStackGet, self).setUp()
87+ self.conf = self.get_stack(self)
88+
89 def test_get_for_empty_stack(self):
90- conf = self.get_stack(self)
91- self.assertEquals(None, conf.get('foo'))
92+ self.assertEquals(None, self.conf.get('foo'))
93
94 def test_get_hook(self):
95- conf = self.get_stack(self)
96- conf.store._load_from_string('foo=bar')
97+ self.conf.store._load_from_string('foo=bar')
98 calls = []
99 def hook(*args):
100 calls.append(args)
101 config.ConfigHooks.install_named_hook('get', hook, None)
102 self.assertLength(0, calls)
103- value = conf.get('foo')
104+ value = self.conf.get('foo')
105 self.assertEquals('bar', value)
106 self.assertLength(1, calls)
107- self.assertEquals((conf, 'foo', 'bar'), calls[0])
108-
109+ self.assertEquals((self.conf, 'foo', 'bar'), calls[0])
110+
111+
112+class TestStackGetWithConverter(TestStackGet):
113+
114+ def setUp(self):
115+ super(TestStackGetWithConverter, self).setUp()
116+ self.overrideAttr(config, 'option_registry', registry.Registry())
117+ self.registry = config.option_registry
118+
119+ def register_bool_option(self, name, default):
120+ b = config.Option(name, default=default,
121+ from_unicode=config.bool_from_store)
122+ self.registry.register(b.name, b, help='A boolean.')
123+
124+ def test_get_with_bool_not_defined_default_true(self):
125+ self.register_bool_option('foo', True)
126+ self.assertEquals(True, self.conf.get('foo'))
127+
128+ def test_get_with_bool_not_defined_default_false(self):
129+ self.register_bool_option('foo', False)
130+ self.assertEquals(False, self.conf.get('foo'))
131+
132+ def test_get_with_bool_converter_not_default(self):
133+ self.register_bool_option('foo', False)
134+ self.conf.store._load_from_string('foo=yes')
135+ self.assertEquals(True, self.conf.get('foo'))
136+
137+ def test_get_with_bool_converter_invalid_string(self):
138+ self.register_bool_option('foo', False)
139+ self.conf.store._load_from_string('foo=not-a-boolean')
140+ self.assertEquals(False, self.conf.get('foo'))
141+
142+ def test_get_with_bool_converter_invalid_list(self):
143+ self.register_bool_option('foo', False)
144+ self.conf.store._load_from_string('foo=not,a,boolean')
145+ self.assertEquals(False, self.conf.get('foo'))
146
147 class TestStackSet(TestStackWithTransport):
148
149
150=== modified file 'doc/en/release-notes/bzr-2.4.txt'
151--- doc/en/release-notes/bzr-2.4.txt 2011-08-23 15:05:57 +0000
152+++ doc/en/release-notes/bzr-2.4.txt 2011-08-24 08:04:25 +0000
153@@ -35,6 +35,9 @@
154 * ``config.LocationMatcher`` properly excludes unrelated sections.
155 (Vincent Ladeuil, #829237)
156
157+* ``dirstate.fdatasync`` and ``repository.fdatasync`` can now properly be
158+ disabled. (Vincent Ladeuil, #824513)
159+
160 * Fix i18n use when no environment variables are set. (Jelmer Vernooij, #810701)
161
162 Documentation

Subscribers

People subscribed via source and target branches