Rev 5754: Properly use MutableSection for write operations. in file:///home/vila/src/bzr/experimental/config/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Wed Apr 6 07:59:42 UTC 2011
At file:///home/vila/src/bzr/experimental/config/
------------------------------------------------------------
revno: 5754
revision-id: v.ladeuil+lp at free.fr-20110406075942-zbw862cv0ioufx7h
parent: v.ladeuil+lp at free.fr-20110405173953-n5rsmhxkytx0nk1d
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: config-stack
timestamp: Wed 2011-04-06 09:59:42 +0200
message:
Properly use MutableSection for write operations.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2011-04-05 17:39:53 +0000
+++ b/bzrlib/config.py 2011-04-06 07:59:42 +0000
@@ -2183,12 +2183,19 @@
class ConfigStack(object):
"""A stack of configurations where an option can be defined"""
- def __init__(self, sections, store=None):
+ def __init__(self, sections, mutable_section=None):
+ """Creates a stack of sections with an optional store for changes.
+
+ :param sections: A list of ReadOnlySection or callables that returns an
+ iterable of ReadOnlySection.
+
+ :param mutable_section: A MutableSection where changes are recorded.
+ """
self.sections = sections
- self.store = store
+ self.mutable_section = mutable_section
def get(self, name):
- """Return the value from the first definition found in the list"""
+ """Return the value from the first definition found in the sections"""
value = None
for s in self.sections:
if callable(s):
@@ -2203,7 +2210,7 @@
return value
def set(self, name, value):
- self.store.set_option(name, value)
+ self.mutable_section.set(name, value)
class cmd_config(commands.Command):
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py 2011-04-05 17:39:53 +0000
+++ b/bzrlib/tests/test_config.py 2011-04-06 07:59:42 +0000
@@ -2068,7 +2068,8 @@
def test_simple_set(self):
store = config.ConfigObjStore.from_string(
'foo=bar', self.get_transport(), 'test.conf')
- conf = config.ConfigStack(list(store.get_sections()), store)
+ conf = config.ConfigStack(
+ [store.get_sections], store.get_mutable_section(None))
self.assertEquals('bar', conf.get('foo'))
conf.set('foo', 'baz')
# Did we get it back ?
@@ -2077,7 +2078,8 @@
def test_set_creates_a_new_section(self):
store = config.ConfigObjStore.from_string(
'', self.get_transport(), 'test.conf')
- conf = config.ConfigStack([store.get_sections], store)
+ conf = config.ConfigStack(
+ [store.get_sections], store.get_mutable_section(None))
conf.set('foo', 'baz')
self.assertEquals, 'baz', conf.get('foo')
More information about the bazaar-commits
mailing list