Rev 4213: catch-all handler for filter stack lookup (Ian clatworthy) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Sun Mar 29 05:38:21 BST 2009


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 4213
revision-id: pqm at pqm.ubuntu.com-20090329043818-5luxyk8q3opz4ulu
parent: pqm at pqm.ubuntu.com-20090328160924-5137lk8zmtp34059
parent: ian.clatworthy at canonical.com-20090329034421-g76md4siq68xpyyh
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Sun 2009-03-29 05:38:18 +0100
message:
  catch-all handler for filter stack lookup (Ian clatworthy)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/filters/__init__.py     __init__.py-20080416080515-mkxl29amuwrf6uir-2
  bzrlib/tests/test_filters.py   test_filters.py-20080417120614-tc3zok0vvvprsc99-1
    ------------------------------------------------------------
    revno: 4212.1.1
    revision-id: ian.clatworthy at canonical.com-20090329034421-g76md4siq68xpyyh
    parent: pqm at pqm.ubuntu.com-20090328160924-5137lk8zmtp34059
    parent: ian.clatworthy at canonical.com-20090329030523-72tjfcxqp7e3h0yz
    committer: Ian Clatworthy <ian.clatworthy at canonical.com>
    branch nick: ianc-integration
    timestamp: Sun 2009-03-29 13:44:21 +1000
    message:
      catch-all handler for filter stack lookup (Ian clatworthy)
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/filters/__init__.py     __init__.py-20080416080515-mkxl29amuwrf6uir-2
      bzrlib/tests/test_filters.py   test_filters.py-20080417120614-tc3zok0vvvprsc99-1
    ------------------------------------------------------------
    revno: 4210.3.2
    revision-id: ian.clatworthy at canonical.com-20090329030523-72tjfcxqp7e3h0yz
    parent: ian.clatworthy at canonical.com-20090328024914-ziswwrnuedoktf28
    committer: Ian Clatworthy <ian.clatworthy at canonical.com>
    branch nick: filters.fallback
    timestamp: Sun 2009-03-29 13:05:23 +1000
    message:
      tweak docstring for lazy content filter registration
    modified:
      bzrlib/filters/__init__.py     __init__.py-20080416080515-mkxl29amuwrf6uir-2
    ------------------------------------------------------------
    revno: 4210.3.1
    revision-id: ian.clatworthy at canonical.com-20090328024914-ziswwrnuedoktf28
    parent: pqm at pqm.ubuntu.com-20090327165538-lustxviiwnrfg2u2
    committer: Ian Clatworthy <ian.clatworthy at canonical.com>
    branch nick: filters.fallback
    timestamp: Sat 2009-03-28 12:49:14 +1000
    message:
      catch-all handler for unknown filter preference values
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/filters/__init__.py     __init__.py-20080416080515-mkxl29amuwrf6uir-2
      bzrlib/tests/test_filters.py   test_filters.py-20080417120614-tc3zok0vvvprsc99-1
=== modified file 'NEWS'
--- a/NEWS	2009-03-28 14:24:46 +0000
+++ b/NEWS	2009-03-29 03:44:21 +0000
@@ -231,6 +231,12 @@
   make visible data inserted into the repository by a smart server
   fetch operation. (Robert Collins, Andrew Bennetts)
 
+* ``register_filter_stack_map`` now takes an optional fallback parameter,
+  a callable to invoke if a preference has a value not in the map
+  of filter stacks. This enhancement allows, for example,  bzr-svn to
+  handle existing svn properties that define a list of keywords to be
+  expanded.  (Ian Clatworthy)
+
 * ``RemoteRepository`` will now negatively cache missing revisions during
   ``get_parent_map`` while read-locked. Write-locks are unaffected.
   (Robert Collins, Andrew Bennetts)

=== modified file 'bzrlib/filters/__init__.py'
--- a/bzrlib/filters/__init__.py	2009-03-24 05:12:24 +0000
+++ b/bzrlib/filters/__init__.py	2009-03-29 03:05:23 +0000
@@ -196,18 +196,23 @@
 _stack_cache = {}
 
 
-def register_filter_stack_map(name, stack_map):
+def register_filter_stack_map(name, stack_map, fallback=None):
     """Register the filter stacks to use for various preference values.
 
     :param name: the preference/filter-stack name
     :param stack_map: a dictionary where
       the keys are preference values to match and
       the values are the matching stack of filters for each
+    :param fallback: if non-None, a callable that will be
+      invoked if a preference value is found that doesn't
+      match a key in the stack_map. The callable is expected
+      to take the value as a parameter and either return
+      the matching stack of filters or None if none.
     """
     if name in _filter_stacks_registry:
         raise errors.BzrError(
             "filter stack for %s already installed" % name)
-    _filter_stacks_registry.register(name, stack_map)
+    _filter_stacks_registry.register(name, (stack_map, fallback))
 
 
 def lazy_register_filter_stack_map(name, module_name, member_name):
@@ -215,7 +220,8 @@
 
     :param name: the preference/filter-stack name
     :param module_name: The python path to the module of the filter stack map.
-    :param member_name: The name of the filter stack map in the module.
+    :param member_name: The name of the (filter stack map, fallback) tuple
+      in the module.
     """
     if name in _filter_stacks_registry:
         raise errors.BzrError(
@@ -246,11 +252,13 @@
     stack = []
     for k, v in preferences:
         try:
-            stacks_by_values = _filter_stacks_registry.get(k)
+            stacks_by_values, fallback = _filter_stacks_registry.get(k)
         except KeyError:
             # Some preferences may not have associated filters
             continue
         items = stacks_by_values.get(v)
+        if items is None and fallback is not None:
+            items = fallback(v)
         if items:
             stack.extend(items)
     _stack_cache[preferences] = stack

=== modified file 'bzrlib/tests/test_filters.py'
--- a/bzrlib/tests/test_filters.py	2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/test_filters.py	2009-03-28 02:49:14 +0000
@@ -111,8 +111,9 @@
 
 class TestFilterStackMaps(TestCase):
 
-    def _register_map(self, pref, stk1, stk2):
-        register_filter_stack_map(pref, {'v1': stk1, 'v2': stk2})
+    def _register_map(self, pref, stk1, stk2, fallback=None):
+        register_filter_stack_map(pref, {'v1': stk1, 'v2': stk2},
+            fallback=fallback)
 
     def test_filter_stack_maps(self):
         # Save the current registry
@@ -157,3 +158,25 @@
         finally:
             # Restore the real registry
             filters._reset_registry(original_registry)
+
+    def test_filter_stack_map_with_callback(self):
+        a_stack = [ContentFilter('b', 'c')]
+        d_stack = [ContentFilter('d', 'D')]
+        z_stack = [ContentFilter('y', 'x'), ContentFilter('w', 'v')]
+        def my_fallback(value):
+            if value == 'v3':
+                return d_stack
+            else:
+                return None
+        # Save the current registry
+        original_registry = filters._reset_registry()
+        try:
+            # Test registration
+            self._register_map('foo', a_stack, z_stack, my_fallback)
+            self.assertEqual(['foo'], _get_registered_names())
+            # Test lookup of a value only handled by the fallback
+            prefs = (('foo','v3'),)
+            self.assertEqual(d_stack, _get_filter_stack_for(prefs))
+        finally:
+            # Restore the real registry
+            filters._reset_registry(original_registry)




More information about the bazaar-commits mailing list