Rev 6408: Fix {relpath} support, realizing that when a section ends with a glob, it's not obivous to decide what should be done. in file:///home/vila/src/bzr/bugs/832046-globs-store-ordered/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Thu Dec 22 17:45:49 UTC 2011
At file:///home/vila/src/bzr/bugs/832046-globs-store-ordered/
------------------------------------------------------------
revno: 6408
revision-id: v.ladeuil+lp at free.fr-20111222174549-8r3s2uulcj7pav2g
parent: v.ladeuil+lp at free.fr-20111222165339-i1da5m6pa96nmjjj
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 832046-globs-store-ordered
timestamp: Thu 2011-12-22 18:45:49 +0100
message:
Fix {relpath} support, realizing that when a section ends with a glob, it's not obivous to decide what should be done.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2011-12-22 16:53:39 +0000
+++ b/bzrlib/config.py 2011-12-22 17:45:49 +0000
@@ -3349,11 +3349,11 @@
return value
-class GlobOrderedMatcher(SectionMatcher):
+class StartingPathMatcher(SectionMatcher):
"""Select sections for a given location respecting the Store order."""
def __init__(self, store, location):
- super(GlobOrderedMatcher, self).__init__(store)
+ super(StartingPathMatcher, self).__init__(store)
if location.startswith('file://'):
location = urlutils.local_path_from_url(location)
self.location = location
@@ -3367,6 +3367,7 @@
The returned section are therefore returned in the reversed order so
the most specific ones can be found first.
"""
+ location_parts = self.location.rstrip('/').split('/')
store = self.store
sections = []
# Later sections are more specific, they should be returned first
@@ -3377,10 +3378,14 @@
continue
section_path = section.id
if section_path.startswith('file://'):
+ # the location is already a local path or URL, convert the
+ # section to the same format
section_path = urlutils.local_path_from_url(section)
if (self.location.startswith(section_path)
or fnmatch.fnmatch(self.location, section_path)):
- yield store, LocationSection(section, self.location)
+ section_parts = section_path.rstrip('/').split('/')
+ extra_path = '/'.join(location_parts[len(section_parts):])
+ yield store, LocationSection(section, extra_path)
class LocationMatcher(SectionMatcher):
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py 2011-12-22 16:53:39 +0000
+++ b/bzrlib/tests/test_config.py 2011-12-22 17:45:49 +0000
@@ -3303,17 +3303,17 @@
self.assertEquals(expected_location, matcher.location)
-class TestGlobOrderedMatcher(TestStore):
+class TestStartingPathMatcher(TestStore):
def setUp(self):
- super(TestGlobOrderedMatcher, self).setUp()
+ super(TestStartingPathMatcher, self).setUp()
self.matcher = config.NameMatcher
# Any simple store is good enough
self.store = config.IniFileStore()
def assertSectionIDs(self, expected, location, content):
self.store._load_from_string(content)
- matcher = config.GlobOrderedMatcher(self.store, location)
+ matcher = config.StartingPathMatcher(self.store, location)
sections = list(matcher.get_sections())
self.assertLength(len(expected), sections)
self.assertEqual(expected, [section.id for _, section in sections])
@@ -3322,14 +3322,17 @@
def test_empty(self):
self.assertSectionIDs([], self.test_dir, '')
- def test_no_name_included_when_present(self):
+ def test_no_name_section_included_when_present(self):
# Note that other tests will cover the case where the no-name section
# is empty and as such, not included.
- self.assertSectionIDs(['/foo/bar', '/foo', None], '/foo/bar/baz', '''\
+ sections = self.assertSectionIDs(['/foo/bar', '/foo', None],
+ '/foo/bar/baz', '''\
option = defined so the no-name section exists
[/foo]
[/foo/bar]
''')
+ self.assertEquals(['baz', 'bar/baz', '/foo/bar/baz'],
+ [s.locals['relpath'] for _, s in sections])
def test_order_reversed(self):
self.assertSectionIDs(['/foo/bar', '/foo'], '/foo/bar/baz', '''\
@@ -3345,13 +3348,18 @@
''')
def test_glob_included(self):
- self.assertSectionIDs(['/foo/*/baz', '/foo/b*', '/foo'],
- '/foo/bar/baz', '''\
+ sections = self.assertSectionIDs(['/foo/*/baz', '/foo/b*', '/foo'],
+ '/foo/bar/baz', '''\
[/foo]
[/foo/qux]
[/foo/b*]
[/foo/*/baz]
''')
+ # Note that 'baz' as a relpath for /foo/b* is not fully correct, but
+ # nothing really does... as far using {relpath} to append it to
+ # something else, this seems good enough though.
+ self.assertEquals(['', 'baz', 'bar/baz'],
+ [s.locals['relpath'] for _, s in sections])
def test_respect_order(self):
self.assertSectionIDs(['/foo', '/foo/b*', '/foo/*/baz'],
=== modified file 'doc/developers/configuration.txt'
--- a/doc/developers/configuration.txt 2011-12-22 16:39:36 +0000
+++ b/doc/developers/configuration.txt 2011-12-22 17:45:49 +0000
@@ -303,8 +303,8 @@
* ``LocationMatcher(store, location)``: To select all sections that match
``location`` sorted by decreasing number of path components.
-* ``GlobOrderedMatcher(store, location)``: To select all sections that match
- ``location`` in the order they appear in the ``store``.
+* ``StartingPathMatcher(store, location)``: To select all sections that
+ match ``location`` in the order they appear in the ``store``.
Stacks
------
=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt 2011-12-22 16:53:39 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt 2011-12-22 17:45:49 +0000
@@ -128,7 +128,7 @@
of the ``socket``, ``ssl`` and ``urllib`` modules for
local bzr operations. (Jelmer Vernooij)
-* Configuration stacks can now use ``GlobOrderedMatcher`` to select the
+* Configuration stacks can now use ``StartingPathMatcher`` to select the
sections matching a location while respecting the order chosen by the user
in the configuration file: from generic sections to specific
sections. (Vincent Ladeuil, #832046).
More information about the bazaar-commits
mailing list