Rev 5770: Merge the use of _filter_for_location_by_parts, uglier, but better for in file:///home/vila/src/bzr/experimental/config/

Vincent Ladeuil v.ladeuil+lp at free.fr
Fri Apr 8 13:39:55 UTC 2011


At file:///home/vila/src/bzr/experimental/config/

------------------------------------------------------------
revno: 5770
revision-id: v.ladeuil+lp at free.fr-20110408133955-14i302k84i4u5fso
parent: v.ladeuil+lp at free.fr-20110408132754-cbvbvgpk1sprs3on
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: config-section-matchers
timestamp: Fri 2011-04-08 15:39:55 +0200
message:
  Merge the use of _filter_for_location_by_parts, uglier, but better for
  maintenance.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2011-04-08 13:27:54 +0000
+++ b/bzrlib/config.py	2011-04-08 13:39:55 +0000
@@ -2372,14 +2372,23 @@
 
     def get_sections(self):
         # Override the default implementation as we want to change the order
-        sections = []
-        for section in self.store.get_sections():
-            match = _match_section_by_parts(section.id, self.location)
-            if match is not None:
-                length, extra_path = match
-                sections.append(LocationSection(section, length, extra_path))
+
+        # The following is a bit hackish but ensures compatibility with
+        # LocationConfig by reusing the same code
+        sections = list(self.store.get_sections())
+        filtered_sections = _filter_for_location_by_parts(
+            [s.id for s in sections], self.location)
+        iter_sections = iter(sections)
+        matching_sections = []
+        for length, section_id, extra_path 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))
         # We want the longest (aka more specific) locations first
-        sections = sorted(sections, key=lambda section: section.length,
+        sections = sorted(matching_sections, key=lambda section: section.length,
                           reverse=True)
         # Sections mentioning 'ignore_parents' restrict the selection
         for section in sections:



More information about the bazaar-commits mailing list