Rev 6168: Emit a warning when bzrlib.intialize) has not been called in file:///home/vila/src/bzr/bugs/863401-library-state/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Fri Sep 30 17:52:25 UTC 2011
At file:///home/vila/src/bzr/bugs/863401-library-state/
------------------------------------------------------------
revno: 6168
revision-id: v.ladeuil+lp at free.fr-20110930175225-03pqlfa6lf7tdnqz
parent: v.ladeuil+lp at free.fr-20110929155058-zgbecmx1huzktegm
fixes bug: https://launchpad.net/bugs/863401
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: 863401-library-state
timestamp: Fri 2011-09-30 19:52:25 +0200
message:
Emit a warning when bzrlib.intialize) has not been called
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2011-09-29 15:50:58 +0000
+++ b/bzrlib/config.py 2011-09-30 17:52:25 +0000
@@ -91,6 +91,7 @@
debug,
errors,
lazy_regex,
+ library_state,
lockdir,
mail_client,
mergetools,
@@ -3271,6 +3272,13 @@
# Mostly for debugging use
return "<config.%s(%s)>" % (self.__class__.__name__, id(self))
+ def _get_overrides(self):
+ # Hack around library_state.initialize never called
+ if bzrlib.global_state is not None:
+ return [bzrlib.global_state.cmdline_overrides]
+ trace.warning("You forgot to use 'with bzrlib.initialize():'")
+ return []
+
class _CompatibleStack(Stack):
"""Place holder for compatibility with previous design.
@@ -3303,7 +3311,7 @@
# Get a GlobalStore
gstore = GlobalStore()
super(GlobalStack, self).__init__(
- [bzrlib.global_state.cmdline_overrides, gstore.get_sections],
+ [self._get_overrides, gstore.get_sections],
gstore)
@@ -3318,7 +3326,7 @@
matcher = LocationMatcher(lstore, location)
gstore = GlobalStore()
super(LocationStack, self).__init__(
- [bzrlib.global_state.cmdline_overrides,
+ [self._get_overrides,
matcher.get_sections, gstore.get_sections],
lstore)
@@ -3332,7 +3340,7 @@
matcher = LocationMatcher(lstore, branch.base)
gstore = GlobalStore()
super(BranchStack, self).__init__(
- [bzrlib.global_state.cmdline_overrides,
+ [self._get_overrides,
matcher.get_sections, bstore.get_sections, gstore.get_sections],
bstore)
self.branch = branch
=== modified file 'bzrlib/tests/test_library_state.py'
--- a/bzrlib/tests/test_library_state.py 2011-01-12 01:01:53 +0000
+++ b/bzrlib/tests/test_library_state.py 2011-09-30 17:52:25 +0000
@@ -16,9 +16,12 @@
"""Tests for BzrLibraryState."""
+import bzrlib
from bzrlib import (
+ config,
library_state,
tests,
+ trace,
ui as _mod_ui
)
from bzrlib.tests import fixtures
@@ -49,3 +52,17 @@
finally:
state.__exit__(None, None, None)
self.assertEqual(['__enter__', '__exit__'], tracer._calls)
+
+ def test_warns_if_not_called(self):
+ self.overrideAttr(bzrlib, 'global_state', None)
+ warnings = []
+ def warning(*args):
+ warnings.append(args[0] % args[1:])
+ self.overrideAttr(trace, 'warning', warning)
+ # Querying for a an option requires a real global_state or emits a
+ # warning
+ c = config.GlobalStack()
+ v = c.get('whatever')
+ self.assertLength(1, warnings)
+ self.assertEquals("You forgot to use 'with bzrlib.initialize():'",
+ warnings[0])
=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt 2011-09-29 15:50:58 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt 2011-09-30 17:52:25 +0000
@@ -55,6 +55,9 @@
turned into a line-basde one when ``INSIDE_EMACS`` is set (which is the
case for all recent emacs versions). (Vincent Ladeuil, #856261)
+* Emit a warning but don't crash if bzrlib.initialize() has not been called.
+ (Vincent Ladeuil, #863401)
+
* Redirects between http and https no longer discard path information
in some cases. (Jelmer Vernooij, #853765)
More information about the bazaar-commits
mailing list