Rev 6036: config.LocationMatcher properly excludes unrelated sections in file:///home/vila/src/bzr/bugs/location-matcher-misses/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Fri Aug 19 08:12:13 UTC 2011
At file:///home/vila/src/bzr/bugs/location-matcher-misses/
------------------------------------------------------------
revno: 6036
revision-id: v.ladeuil+lp at free.fr-20110819081212-zlh8tz1756j5bjhj
parent: pqm at pqm.ubuntu.com-20110818174456-bfxvop3tb9f1b5dn
fixes bug(s): https://launchpad.net/bugs/829237
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: location-matcher-misses
timestamp: Fri 2011-08-19 10:12:12 +0200
message:
config.LocationMatcher properly excludes unrelated sections
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2011-08-11 09:03:18 +0000
+++ b/bzrlib/config.py 2011-08-19 08:12:12 +0000
@@ -2649,30 +2649,34 @@
# We slightly diverge from LocalConfig here by allowing the no-name
# section as the most generic one and the lower priority.
no_name_section = None
- sections = []
+ all_sections = []
# Filter out the no_name_section so _iter_for_location_by_parts can be
# used (it assumes all sections have a name).
for section in self.store.get_sections():
if section.id is None:
no_name_section = section
else:
- sections.append(section)
+ all_sections.append(section)
# Unfortunately _iter_for_location_by_parts deals with section names so
# we have to resync.
filtered_sections = _iter_for_location_by_parts(
- [s.id for s in sections], self.location)
- iter_sections = iter(sections)
+ [s.id for s in all_sections], self.location)
+ iter_all_sections = iter(all_sections)
matching_sections = []
if no_name_section is not None:
matching_sections.append(
LocationSection(no_name_section, 0, self.location))
for section_id, extra_path, length in filtered_sections:
- # a section id is unique for a given store so it's safe to iterate
- # again
- section = iter_sections.next()
- if section_id == section.id:
- matching_sections.append(
- LocationSection(section, length, extra_path))
+ # a section id is unique for a given store so it's safe to take the
+ # first matching section while iterating. Also, all filtered
+ # sections are part of 'all_sections' and will always be found
+ # there.
+ while True:
+ section = iter_all_sections.next()
+ if section_id == section.id:
+ matching_sections.append(
+ LocationSection(section, length, extra_path))
+ break
return matching_sections
def get_sections(self):
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py 2011-06-22 13:53:20 +0000
+++ b/bzrlib/tests/test_config.py 2011-08-19 08:12:12 +0000
@@ -2803,6 +2803,32 @@
def get_store(self, file_name):
return config.IniFileStore(self.get_readonly_transport(), file_name)
+ def test_unrelated_section_excluded(self):
+ store = self.get_store('foo.conf')
+ store._load_from_string('''
+[/foo]
+section=/foo
+[/foo/baz]
+section=/foo/baz
+[/foo/bar]
+section=/foo/bar
+[/foo/bar/baz]
+section=/foo/bar/baz
+[/quux/quux]
+section=/quux/quux
+''')
+ self.assertEquals(['/foo', '/foo/baz', '/foo/bar', '/foo/bar/baz',
+ '/quux/quux'],
+ [section.id for section in store.get_sections()])
+ matcher = config.LocationMatcher(store, '/foo/bar/quux')
+ sections = list(matcher.get_sections())
+ self.assertEquals([3, 2],
+ [section.length for section in sections])
+ self.assertEquals(['/foo/bar', '/foo'],
+ [section.id for section in sections])
+ self.assertEquals(['quux', 'bar/quux'],
+ [section.extra_path for section in sections])
+
def test_more_specific_sections_first(self):
store = self.get_store('foo.conf')
store._load_from_string('''
=== modified file 'doc/en/release-notes/bzr-2.4.txt'
--- a/doc/en/release-notes/bzr-2.4.txt 2011-08-15 07:29:01 +0000
+++ b/doc/en/release-notes/bzr-2.4.txt 2011-08-19 08:12:12 +0000
@@ -32,6 +32,9 @@
.. Fixes for situations where bzr would previously crash or give incorrect
or undesirable results.
+* ``config.LocationMatcher`` properly excludes unrelated sections.
+ (Vincent Ladeuil, #829237)
+
Documentation
*************
More information about the bazaar-commits
mailing list