Rev 5775: Merge config-stack into config-concrete-stacks in file:///home/vila/src/bzr/experimental/config/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Tue May 3 15:04:22 UTC 2011
At file:///home/vila/src/bzr/experimental/config/
------------------------------------------------------------
revno: 5775 [merge]
revision-id: v.ladeuil+lp at free.fr-20110503150422-pyd7vs36ah55o5pg
parent: v.ladeuil+lp at free.fr-20110503140018-f7i5f7ankhqgnevc
parent: v.ladeuil+lp at free.fr-20110503150359-a3j06zh4k3wzezc2
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: config-concrete-stacks
timestamp: Tue 2011-05-03 17:04:22 +0200
message:
Merge config-stack into config-concrete-stacks
modified:
bzrlib/config.py config.py-20051011043216-070c74f4e9e338e8
bzrlib/tests/test_config.py testconfig.py-20051011041908-742d0c15d8d8c8eb
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2011-05-03 14:00:18 +0000
+++ b/bzrlib/config.py 2011-05-03 15:04:22 +0000
@@ -2447,19 +2447,19 @@
class Stack(object):
"""A stack of configurations where an option can be defined"""
- def __init__(self, sections=None, get_mutable_section=None):
+ def __init__(self, sections_def, mutable_section_def=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 sections_def: A list of Section or callables that returns an
+ iterable of Section. This defines the Sections for the Stack and
+ can be called repeatedly if needed.
- :param get_mutable_section: A callable that returns a MutableSection
- where changes are recorded.
+ :param mutable_section_def: A callable that returns a MutableSection
+ where changes are recorded. This defines the MutableSection and can
+ be called repeatedly.
"""
- if sections is None:
- sections = []
- self.sections = sections
- self.get_mutable_section = get_mutable_section
+ self.sections_def = sections_def
+ self.mutable_section_def = mutable_section_def
def get(self, name):
"""Return the *first* option value found in the sections.
@@ -2470,10 +2470,12 @@
in which sections it can be defined. Both of these (section and option
existence) require loading the store (even partially).
"""
+ # FIXME: No caching of options nor sections yet -- vila 20110503
+
# Ensuring lazy loading is achieved by delaying section matching until
# it can be avoided anymore by using callables to describe (possibly
# empty) section lists.
- for section_or_callable in self.sections:
+ for section_or_callable in self.sections_def:
# Each section can expand to multiple ones when a callable is used
if callable(section_or_callable):
sections = section_or_callable()
@@ -2492,7 +2494,7 @@
This is where we guarantee that the mutable section is lazily loaded:
this means we won't load the corresponding store before setting a value.
"""
- section = self.get_mutable_section()
+ section = self.mutable_section_def()
section.set(name, value)
def remove(self, name):
@@ -2503,7 +2505,7 @@
an option. In practice the store will often be loaded but this allows
catching some programming errors.
"""
- section = self.get_mutable_section()
+ section = self.mutable_section_def()
section.remove(name)
def __repr__(self):
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py 2011-05-03 14:00:18 +0000
+++ b/bzrlib/tests/test_config.py 2011-05-03 15:04:22 +0000
@@ -2209,7 +2209,7 @@
self.assertEquals('baz', conf_stack.get('foo'))
def test_get_for_empty_stack(self):
- conf_stack = config.Stack()
+ conf_stack = config.Stack([])
self.assertEquals(None, conf_stack.get('foo'))
def test_get_for_empty_section_callable(self):
More information about the bazaar-commits
mailing list