Merge lp:~vila/bzr/829237-location-matcher-misses 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: 6037
Proposed branch: lp:~vila/bzr/829237-location-matcher-misses
Merge into: lp:bzr/2.4
Diff against target: 98 lines (+43/-10)
3 files modified
bzrlib/config.py (+14/-10)
bzrlib/tests/test_config.py (+26/-0)
doc/en/release-notes/bzr-2.4.txt (+3/-0)
To merge this branch: bzr merge lp:~vila/bzr/829237-location-matcher-misses
Reviewer Review Type Date Requested Status
Jonathan Riddell (community) Approve
Review via email: mp+72151@code.launchpad.net

Commit message

config.LocationMatcher properly excludes unrelated sections

Description of the change

config.LocationMatcher wasn't selecting the right sections when
unrelated sections were existing:

[/foo]
section=/foo
[/foo/baz]
section=/foo/baz
[/foo/bar]
section=/foo/bar

was selecting only /foo when queried for /foor/bar/quux

The fix is trivial.

I'm targetting 2.4 as at least the fdatasync options use
LocationStack.

To post a comment you must log in.
Revision history for this message
Jonathan Riddell (jr) wrote :

I'm not convinced I understand the logic change here I'm afraid. However the test looks correct so I trust the change :)

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

sent to pqm by email

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

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 8/19/2011 10:18 AM, Vincent Ladeuil wrote:
> Vincent Ladeuil has proposed merging
> lp:~vila/bzr/829237-location-matcher-misses into lp:bzr/2.4.
>
> Requested reviews: bzr-core (bzr-core) Related bugs: Bug #829237 in
> Bazaar: "config.LocationMatcher may miss"
> https://bugs.launchpad.net/bzr/+bug/829237
>
> For more details, see:
> https://code.launchpad.net/~vila/bzr/829237-location-matcher-misses/+merge/72151
>
> config.LocationMatcher wasn't selecting the right sections when
> unrelated sections were existing:
>
> [/foo] section=/foo [/foo/baz] section=/foo/baz [/foo/bar]
> section=/foo/bar
>
> was selecting only /foo when queried for /foor/bar/quux
>
> The fix is trivial.
>
> I'm targetting 2.4 as at least the fdatasync options use
> LocationStack.

+ while True:
+ section = iter_all_sections.next()
+ if section_id == section.id:
+ matching_sections.append(
+ LocationSection(section, length, extra_path))
+ break

^- This seems like a good way to get either an infinite loop, or a
StopIteration exception. I think you want:

while True:
  try:
    section = ...
  except StopIteration:
    break

Do we already catch StopIteration somewhere else?

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk5SORcACgkQJdeBCYSNAAM2wgCg04d/TXBwFRH67gz/tNGOyYpJ
TEgAniKzw7ftU1lYEw3+Z6jy6SLBfMl6
=2FoX
-----END PGP SIGNATURE-----

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-11 09:03:18 +0000
3+++ bzrlib/config.py 2011-08-19 08:18:23 +0000
4@@ -2649,30 +2649,34 @@
5 # We slightly diverge from LocalConfig here by allowing the no-name
6 # section as the most generic one and the lower priority.
7 no_name_section = None
8- sections = []
9+ all_sections = []
10 # Filter out the no_name_section so _iter_for_location_by_parts can be
11 # used (it assumes all sections have a name).
12 for section in self.store.get_sections():
13 if section.id is None:
14 no_name_section = section
15 else:
16- sections.append(section)
17+ all_sections.append(section)
18 # Unfortunately _iter_for_location_by_parts deals with section names so
19 # we have to resync.
20 filtered_sections = _iter_for_location_by_parts(
21- [s.id for s in sections], self.location)
22- iter_sections = iter(sections)
23+ [s.id for s in all_sections], self.location)
24+ iter_all_sections = iter(all_sections)
25 matching_sections = []
26 if no_name_section is not None:
27 matching_sections.append(
28 LocationSection(no_name_section, 0, self.location))
29 for section_id, extra_path, length in filtered_sections:
30- # a section id is unique for a given store so it's safe to iterate
31- # again
32- section = iter_sections.next()
33- if section_id == section.id:
34- matching_sections.append(
35- LocationSection(section, length, extra_path))
36+ # a section id is unique for a given store so it's safe to take the
37+ # first matching section while iterating. Also, all filtered
38+ # sections are part of 'all_sections' and will always be found
39+ # there.
40+ while True:
41+ section = iter_all_sections.next()
42+ if section_id == section.id:
43+ matching_sections.append(
44+ LocationSection(section, length, extra_path))
45+ break
46 return matching_sections
47
48 def get_sections(self):
49
50=== modified file 'bzrlib/tests/test_config.py'
51--- bzrlib/tests/test_config.py 2011-06-22 13:53:20 +0000
52+++ bzrlib/tests/test_config.py 2011-08-19 08:18:23 +0000
53@@ -2803,6 +2803,32 @@
54 def get_store(self, file_name):
55 return config.IniFileStore(self.get_readonly_transport(), file_name)
56
57+ def test_unrelated_section_excluded(self):
58+ store = self.get_store('foo.conf')
59+ store._load_from_string('''
60+[/foo]
61+section=/foo
62+[/foo/baz]
63+section=/foo/baz
64+[/foo/bar]
65+section=/foo/bar
66+[/foo/bar/baz]
67+section=/foo/bar/baz
68+[/quux/quux]
69+section=/quux/quux
70+''')
71+ self.assertEquals(['/foo', '/foo/baz', '/foo/bar', '/foo/bar/baz',
72+ '/quux/quux'],
73+ [section.id for section in store.get_sections()])
74+ matcher = config.LocationMatcher(store, '/foo/bar/quux')
75+ sections = list(matcher.get_sections())
76+ self.assertEquals([3, 2],
77+ [section.length for section in sections])
78+ self.assertEquals(['/foo/bar', '/foo'],
79+ [section.id for section in sections])
80+ self.assertEquals(['quux', 'bar/quux'],
81+ [section.extra_path for section in sections])
82+
83 def test_more_specific_sections_first(self):
84 store = self.get_store('foo.conf')
85 store._load_from_string('''
86
87=== modified file 'doc/en/release-notes/bzr-2.4.txt'
88--- doc/en/release-notes/bzr-2.4.txt 2011-08-15 07:29:01 +0000
89+++ doc/en/release-notes/bzr-2.4.txt 2011-08-19 08:18:23 +0000
90@@ -32,6 +32,9 @@
91 .. Fixes for situations where bzr would previously crash or give incorrect
92 or undesirable results.
93
94+* ``config.LocationMatcher`` properly excludes unrelated sections.
95+ (Vincent Ladeuil, #829237)
96+
97 Documentation
98 *************
99

Subscribers

People subscribed via source and target branches