Rev 6128: Make config.stacks.get() build the stack and accept context parameters but _get_factory for tests and unforeseen uses. in file:///home/vila/src/bzr/bugs/832036-stack-registry/

Vincent Ladeuil v.ladeuil+lp at free.fr
Tue Sep 6 18:09:31 UTC 2011


At file:///home/vila/src/bzr/bugs/832036-stack-registry/

------------------------------------------------------------
revno: 6128
revision-id: v.ladeuil+lp at free.fr-20110906180930-n7pbe223hg750ys3
parent: v.ladeuil+lp at free.fr-20110906160201-9qss61wdp7rzykbl
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 832036-stack-registry
timestamp: Tue 2011-09-06 20:09:30 +0200
message:
  Make config.stacks.get() build the stack and accept context parameters but _get_factory for tests and unforeseen uses.
-------------- next part --------------
=== modified file 'bzrlib/bzrdir.py'
--- a/bzrlib/bzrdir.py	2011-09-06 16:02:01 +0000
+++ b/bzrlib/bzrdir.py	2011-09-06 18:09:30 +0000
@@ -2288,7 +2288,7 @@
     help='Same as 2a.')
 
 # The current format that is made on 'bzr init'.
-format_name = config.stacks.get('bazaar')().get('default_format')
+format_name = config.stacks.get('bazaar').get('default_format')
 controldir.format_registry.set_default(format_name)
 
 # XXX 2010-08-20 JRV: There is still a lot of code relying on

=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py	2011-09-06 16:02:01 +0000
+++ b/bzrlib/config.py	2011-09-06 18:09:30 +0000
@@ -3326,9 +3326,16 @@
     This registry is queried for a given key and provides a factory that accept
     a context and build the appropriate Stack for this context.
     """
+
+    def get(self, key, *args, **kwargs):
+        return self._get_factory(key)(*args, **kwargs)
+
+    def _get_factory(self, key):
+        return super(StackRegistry, self).get(key)
+
     def get_help(self, key=None):
         """Get the help text associated with the given key"""
-        factory = self.get(key)
+        factory = self._get_factory(key)
         the_help = factory.__doc__
         if callable(the_help):
             return the_help(self, key)

=== modified file 'bzrlib/debug.py'
--- a/bzrlib/debug.py	2011-09-06 16:02:01 +0000
+++ b/bzrlib/debug.py	2011-09-06 18:09:30 +0000
@@ -32,7 +32,7 @@
 
     from bzrlib import config
 
-    c = config.stacks.get('bazaar')()
+    c = config.stacks.get('bazaar')
     for f in c.get('debug_flags'):
         debug_flags.add(f)
 

=== modified file 'bzrlib/dirstate.py'
--- a/bzrlib/dirstate.py	2011-09-06 16:02:01 +0000
+++ b/bzrlib/dirstate.py	2011-09-06 18:09:30 +0000
@@ -451,7 +451,7 @@
         # How many hash changed entries can we have without saving
         self._worth_saving_limit = worth_saving_limit
         self._config_stack = config.stacks.get(
-            'locations')(urlutils.local_path_to_url(path))
+            'locations', urlutils.local_path_to_url(path))
 
     def __repr__(self):
         return "%s(%r)" % (self.__class__.__name__, self._filename)

=== modified file 'bzrlib/i18n.py'
--- a/bzrlib/i18n.py	2011-09-06 16:02:01 +0000
+++ b/bzrlib/i18n.py	2011-09-06 18:09:30 +0000
@@ -136,7 +136,7 @@
 def _get_current_locale():
     if not os.environ.get('LANGUAGE'):
         from bzrlib import config
-        lang = config.stacks.get('bazaar')().get('language')
+        lang = config.stacks.get('bazaar').get('language')
         if lang:
             os.environ['LANGUAGE'] = lang
             return lang

=== modified file 'bzrlib/lockdir.py'
--- a/bzrlib/lockdir.py	2011-09-06 16:02:01 +0000
+++ b/bzrlib/lockdir.py	2011-09-06 18:09:30 +0000
@@ -708,7 +708,7 @@
         # XXX: This really should also use the locationconfig at least, but
         # that seems a bit hard to hook up at the moment. -- mbp 20110329
         # FIXME: The above is still true ;) -- vila 20110811
-        return config.stacks.get('bazaar')()
+        return config.stacks.get('bazaar')
 
 
 class LockHeldInfo(object):

=== modified file 'bzrlib/msgeditor.py'
--- a/bzrlib/msgeditor.py	2011-09-06 16:02:01 +0000
+++ b/bzrlib/msgeditor.py	2011-09-06 18:09:30 +0000
@@ -41,7 +41,7 @@
     except KeyError:
         pass
 
-    e = config.stacks.get('bazaar')().get('editor')
+    e = config.stacks.get('bazaar').get('editor')
     if e is not None:
         yield e, config.config_filename()
 

=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py	2011-09-06 16:02:01 +0000
+++ b/bzrlib/osutils.py	2011-09-06 18:09:30 +0000
@@ -986,7 +986,7 @@
 def report_extension_load_failures():
     if not _extension_load_failures:
         return
-    if config.stacks.get('bazaar')().get('ignore_missing_extensions'):
+    if config.stacks.get('bazaar').get('ignore_missing_extensions'):
         return
     # the warnings framework should by default show this only once
     from bzrlib.trace import warning

=== modified file 'bzrlib/repofmt/pack_repo.py'
--- a/bzrlib/repofmt/pack_repo.py	2011-09-06 16:02:01 +0000
+++ b/bzrlib/repofmt/pack_repo.py	2011-09-06 18:09:30 +0000
@@ -831,7 +831,7 @@
                 set(all_combined).difference([combined_idx]))
         # resumed packs
         self._resumed_packs = []
-        self.config_stack = config.stacks.get('locations')(self.transport.base)
+        self.config_stack = config.stacks.get('locations', self.transport.base)
 
     def __repr__(self):
         return '%s(%r)' % (self.__class__.__name__, self.repo)

=== modified file 'bzrlib/tests/per_workingtree/test_workingtree.py'
--- a/bzrlib/tests/per_workingtree/test_workingtree.py	2011-09-06 16:02:01 +0000
+++ b/bzrlib/tests/per_workingtree/test_workingtree.py	2011-09-06 18:09:30 +0000
@@ -1161,7 +1161,7 @@
 
     def test_set_in_branch(self):
         wt = self.make_wt_with_worth_saving_limit()
-        conf = config.stacks.get('branch')(wt.branch)
+        conf = config.stacks.get('branch', wt.branch)
         conf.set('bzr.workingtree.worth_saving_limit', '20')
         self.assertEqual(20, wt._worth_saving_limit())
         ds = wt.current_dirstate()
@@ -1169,7 +1169,7 @@
 
     def test_invalid(self):
         wt = self.make_wt_with_worth_saving_limit()
-        conf = config.stacks.get('branch')(wt.branch)
+        conf = config.stacks.get('branch', wt.branch)
         conf.set('bzr.workingtree.worth_saving_limit', 'a')
         # If the config entry is invalid, default to 10
         warnings = []

=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py	2011-09-06 16:02:01 +0000
+++ b/bzrlib/tests/test_config.py	2011-09-06 18:09:30 +0000
@@ -132,15 +132,15 @@
 
 
 config.test_stack_builder_registry.register(
-    'bazaar', lambda test: config.stacks.get('bazaar')())
+    'bazaar', lambda test: config.stacks.get('bazaar'))
 config.test_stack_builder_registry.register(
-    'location', lambda test: config.stacks.get('locations')('.'))
+    'location', lambda test: config.stacks.get('locations', '.'))
 
 
 def build_branch_stack(test):
     build_backing_branch(test, 'branch')
     b = branch.Branch.open('branch')
-    return config.stacks.get('branch')(b)
+    return config.stacks.get('branch', b)
 config.test_stack_builder_registry.register('branch', build_branch_stack)
 
 
@@ -151,7 +151,7 @@
      server_class) = transport_remote.get_test_permutations()[0]
     build_backing_branch(test, 'branch', transport_class, server_class)
     b = branch.Branch.open(test.get_url('branch'))
-    return config.stacks.get('branch')(b)
+    return config.stacks.get('branch', b)
 config.test_stack_builder_registry.register('remote_branch',
                                             build_remote_branch_stack)
 
@@ -164,7 +164,7 @@
     # creating a dedicated helper to create only the bzrdir
     build_backing_branch(test, 'branch', transport_class, server_class)
     b = branch.Branch.open(test.get_url('branch'))
-    return config.stacks.get('control-only')(b.bzrdir)
+    return config.stacks.get('control-only', b.bzrdir)
 config.test_stack_builder_registry.register('remote_control',
                                             build_remote_control_stack)
 
@@ -3187,24 +3187,24 @@
 
     def test_register_remove(self):
         self.registry.register('test', config.Stack)
-        self.assertIs(config.Stack, self.registry.get('test'))
+        self.assertIs(config.Stack, self.registry._get_factory('test'))
         self.registry.remove('test')
-        self.assertRaises(KeyError, self.registry.get, 'test')
+        self.assertRaises(KeyError, self.registry._get_factory, 'test')
 
     lazy_stack = config.Stack
 
     def test_register_lazy_remove(self):
         self.registry.register_lazy('test', self.__module__,
                                     'TestStackRegistry.lazy_stack')
-        self.assertIs(self.lazy_stack, self.registry.get('test'))
+        self.assertIs(self.lazy_stack, self.registry._get_factory('test'))
         self.registry.remove('test')
-        self.assertRaises(KeyError, self.registry.get, 'test')
+        self.assertRaises(KeyError, self.registry._get_factory, 'test')
 
     def test_register_override(self):
         self.registry.register('test', config.Stack)
-        self.assertIs(config.Stack, self.registry.get('test'))
+        self.assertIs(config.Stack, self.registry._get_factory('test'))
         self.registry.register('test', self.lazy_stack, override_existing=True)
-        self.assertIs(self.lazy_stack, self.registry.get('test'))
+        self.assertIs(self.lazy_stack, self.registry._get_factory('test'))
 
 
 class TestRegisteredStacks(tests.TestCase):
@@ -3536,7 +3536,7 @@
             string = ''
         # Since we don't save the config we won't strictly require to inherit
         # from TestCaseInTempDir, but an error occurs so quickly...
-        c = config.stacks.get('locations')(location)
+        c = config.stacks.get('locations', location)
         c.store._load_from_string(string)
         return c
 

=== modified file 'bzrlib/tests/test_debug.py'
--- a/bzrlib/tests/test_debug.py	2011-09-06 16:02:01 +0000
+++ b/bzrlib/tests/test_debug.py	2011-09-06 18:09:30 +0000
@@ -33,7 +33,7 @@
         self.assertDebugFlags(['hpss'], 'debug_flags = hpss\n')
 
     def assertDebugFlags(self, expected_flags, conf_bytes):
-        conf = config.stacks.get('bazaar')()
+        conf = config.stacks.get('bazaar')
         conf.store._load_from_string(conf_bytes)
         conf.store.save()
         self.overrideAttr(debug, 'debug_flags', set())

=== modified file 'bzrlib/ui/__init__.py'
--- a/bzrlib/ui/__init__.py	2011-09-06 16:02:01 +0000
+++ b/bzrlib/ui/__init__.py	2011-09-06 18:09:30 +0000
@@ -248,7 +248,7 @@
         """
         # XXX: is the caller supposed to close the resulting object?
         if encoding is None:
-            encoding = config.stacks.get('bazaar')().get('output_encoding')
+            encoding = config.stacks.get('bazaar').get('output_encoding')
         if encoding is None:
             encoding = osutils.get_terminal_encoding(trace=True)
         if encoding_type is None:

=== modified file 'bzrlib/workingtree_4.py'
--- a/bzrlib/workingtree_4.py	2011-09-06 16:02:01 +0000
+++ b/bzrlib/workingtree_4.py	2011-09-06 18:09:30 +0000
@@ -251,7 +251,7 @@
         :return: an integer. -1 means never save.
         """
         # FIXME: We want a WorkingTreeStack here -- vila 20110812
-        conf = config.stacks.get('branch')(self.branch)
+        conf = config.stacks.get('branch', self.branch)
         return conf.get('bzr.workingtree.worth_saving_limit')
 
     def filter_unversioned_files(self, paths):



More information about the bazaar-commits mailing list