Rev 4847: Move the _warn_if_deprecated call from repo.__init__ to in file:///home/vila/src/bzr/reviews/deprecation-warning-preference/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Tue Dec 15 20:32:34 GMT 2009
At file:///home/vila/src/bzr/reviews/deprecation-warning-preference/
------------------------------------------------------------
revno: 4847
revision-id: v.ladeuil+lp at free.fr-20091215203234-d8br6xqfq6pec40z
parent: v.ladeuil+lp at free.fr-20091215153349-lsc6sjk57hvj11fc
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: deprecation-warning-preference
timestamp: Tue 2009-12-15 21:32:34 +0100
message:
Move the _warn_if_deprecated call from repo.__init__ to
repo.lock_{read,write} so that branch.lock_{read,write} can call it. This
makes it possible to access locations.conf and branch.conf.
* bzrlib/tests/blackbox/test_exceptions.py:
(TestDeprecationWarning): Test that the suppress_warning
configuration variable is taken into account.
* bzrlib/repository.py:
(Repository.__init__): Delete very old and obsolete
comments. Don't warn about deprecations yet.
(Repository.lock_write, Repository.lock_read): The repo is about
to be locked, check deprecation.
(Repository._warn_if_deprecated): Use the branch config if
available or the global one othewrwise and check for the
suppress_warning variable.
* bzrlib/remote.py:
(RemoteRepository._warn_if_deprecated): Nothing to do here.
* bzrlib/repofmt/pack_repo.py:
(KnitPackRepository._warn_if_deprecated): Delegate to base class
if needed.
* bzrlib/branch.py:
(BzrBranch.lock_write, BzrBranch.lock_read): Check repo
deprecation.
* bzrlib/help_topics/en/configuration.txt:
Fix the variable name and its description.
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS 2009-11-30 04:49:31 +0000
+++ b/NEWS 2009-12-15 20:32:34 +0000
@@ -26,6 +26,12 @@
* ``bzr commit`` now has a ``--commit-time`` option.
(Alexander Sack, #459276)
+* The ``suppresss_warnings`` configuration option has been introduced and
+ accept the ``format_deprecation`` value to disable the corresponding
+ warning for repositories. It can be set to in either ``bazaar.conf``,
+ ``locations.conf`` or ``branch.conf``.
+ (Ted Gould, Matthew Fuller, Vincent Ladeuil)
+
Bug Fixes
*********
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2009-10-15 02:11:18 +0000
+++ b/bzrlib/branch.py 2009-12-15 20:32:34 +0000
@@ -2137,6 +2137,7 @@
# All-in-one needs to always unlock/lock.
repo_control = getattr(self.repository, 'control_files', None)
if self.control_files == repo_control or not self.is_locked():
+ self.repository._warn_if_deprecated(self)
self.repository.lock_write()
took_lock = True
else:
@@ -2154,6 +2155,7 @@
# All-in-one needs to always unlock/lock.
repo_control = getattr(self.repository, 'control_files', None)
if self.control_files == repo_control or not self.is_locked():
+ self.repository._warn_if_deprecated(self)
self.repository.lock_read()
took_lock = True
else:
=== modified file 'bzrlib/help_topics/en/configuration.txt'
--- a/bzrlib/help_topics/en/configuration.txt 2009-11-30 22:55:37 +0000
+++ b/bzrlib/help_topics/en/configuration.txt 2009-12-15 20:32:34 +0000
@@ -428,11 +428,17 @@
A publically-accessible version of this branch (implying that this version is
not publically-accessible). Used (and set) by ``bzr send``.
-format_deprecation_warning
-~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-A boolean value as to whether the format deprecation warning is shown on
-repositories that are using deprecated formats.
+suppress_warnings
+~~~~~~~~~~~~~~~~~
+
+A list of strings, each string represent a warning that can be emitted by
+bzr. Mentioning a warning in this list tells bzr to not emit it.
+
+Valid values:
+
+* ``format_deprecation``:
+ whether the format deprecation warning is shown on repositories that are
+ using deprecated formats.
Branch type specific options
=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py 2009-11-11 06:50:40 +0000
+++ b/bzrlib/remote.py 2009-12-15 20:32:34 +0000
@@ -951,6 +951,11 @@
def is_write_locked(self):
return self._lock_mode == 'w'
+ def _warn_if_deprecated(self, branch=None):
+ # If we have a real repository, the check will be done there, if we
+ # don't the check will be done remotely.
+ pass
+
def lock_read(self):
# wrong eventually - want a local lock cache context
if not self._lock_mode:
=== modified file 'bzrlib/repofmt/pack_repo.py'
--- a/bzrlib/repofmt/pack_repo.py 2009-10-29 05:54:49 +0000
+++ b/bzrlib/repofmt/pack_repo.py 2009-12-15 20:32:34 +0000
@@ -2234,16 +2234,10 @@
self._reconcile_fixes_text_parents = True
self._reconcile_backsup_inventory = False
- def _warn_if_deprecated(self):
+ def _warn_if_deprecated(self, branch=None):
# This class isn't deprecated, but one sub-format is
if isinstance(self._format, RepositoryFormatKnitPack5RichRootBroken):
- from bzrlib import repository
- if repository._deprecation_warning_done:
- return
- repository._deprecation_warning_done = True
- warning("Format %s for %s is deprecated - please use"
- " 'bzr upgrade --1.6.1-rich-root'"
- % (self._format, self.bzrdir.transport.base))
+ super(KnitPackRepository, self)._warn_if_deprecated(branch)
def _abort_write_group(self):
self.revisions._index._key_dependencies.clear()
=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py 2009-11-30 22:50:57 +0000
+++ b/bzrlib/repository.py 2009-12-15 20:32:34 +0000
@@ -24,6 +24,7 @@
bzrdir,
check,
chk_map,
+ config,
debug,
errors,
fetch as _mod_fetch,
@@ -62,7 +63,6 @@
from bzrlib import registry
from bzrlib.trace import (
log_exception_quietly, note, mutter, mutter_callsite, warning)
-from bzrlib.config import GlobalConfig
# Old formats display a warning, but only once
@@ -1305,11 +1305,6 @@
self._reconcile_does_inventory_gc = True
self._reconcile_fixes_text_parents = False
self._reconcile_backsup_inventory = True
- # not right yet - should be more semantically clear ?
- #
- # TODO: make sure to construct the right store classes, etc, depending
- # on whether escaping is required.
- self._warn_if_deprecated()
self._write_group = None
# Additional places to query for data.
self._fallback_repositories = []
@@ -1387,6 +1382,7 @@
locked = self.is_locked()
result = self.control_files.lock_write(token=token)
if not locked:
+ self._warn_if_deprecated()
self._note_lock('w')
for repo in self._fallback_repositories:
# Writes don't affect fallback repos
@@ -1398,6 +1394,7 @@
locked = self.is_locked()
self.control_files.lock_read()
if not locked:
+ self._warn_if_deprecated()
self._note_lock('r')
for repo in self._fallback_repositories:
repo.lock_read()
@@ -2779,15 +2776,22 @@
result.check(callback_refs)
return result
- def _warn_if_deprecated(self):
+ def _warn_if_deprecated(self, branch=None):
global _deprecation_warning_done
if _deprecation_warning_done:
return
- _deprecation_warning_done = True
- if GlobalConfig().get_user_option('format_deprecation_warning'):
- return
- warning("Format %s for %s is deprecated - please use 'bzr upgrade' to get better performance"
- % (self._format, self.bzrdir.transport.base))
+ try:
+ if branch is None:
+ conf = config.GlobalConfig()
+ else:
+ conf = branch.get_config()
+ if conf.suppress_warning('format_deprecation'):
+ return
+ warning("Format %s for %s is deprecated -"
+ " please use 'bzr upgrade' to get better performance"
+ % (self._format, self.bzrdir.transport.base))
+ finally:
+ _deprecation_warning_done = True
def supports_rich_root(self):
return self._format.rich_root_data
=== modified file 'bzrlib/tests/blackbox/test_exceptions.py'
--- a/bzrlib/tests/blackbox/test_exceptions.py 2009-08-20 06:25:02 +0000
+++ b/bzrlib/tests/blackbox/test_exceptions.py 2009-12-15 20:32:34 +0000
@@ -22,8 +22,11 @@
from bzrlib import (
bzrdir,
+ config,
errors,
+ osutils,
repository,
+ tests,
trace,
)
@@ -45,18 +48,70 @@
self.assertContainsRe(err, r'Bazaar has encountered an internal error')
-class TestDeprecationWarning(TestCaseInTempDir):
+class TestDeprecationWarning(tests.TestCaseWithTransport):
+ """The deprecation warning is controlled via a global variable:
+ repository._deprecation_warning_done. As such, it can be emitted only once
+ during a bzr invocation, no matter how many repositories are involved.
+
+ It would be better if it was a repo attribute instead but that's far more
+ work than I want to do right now -- vila 20091215.
+ """
+
+ def setUp(self):
+ super(TestDeprecationWarning, self).setUp()
+ self.disable_deprecation_warning()
+
+ def enable_deprecation_warning(self, repo=None):
+ """repo is not used yet since _deprecation_warning_done is a global"""
+ repository._deprecation_warning_done = False
+
+ def disable_deprecation_warning(self, repo=None):
+ """repo is not used yet since _deprecation_warning_done is a global"""
+ repository._deprecation_warning_done = True
+
+ def make_obsolete_repo(self, path):
+ # We don't want the deprecation raising during the repo creation
+ tree = self.make_branch_and_tree(path, format=bzrdir.BzrDirFormat5())
+ return tree
+
+ def check_warning(self, present):
+ if present:
+ check = self.assertContainsRe
+ else:
+ check = self.assertNotContainsRe
+ check(self._get_log(keep_log_file=True), 'WARNING.*bzr upgrade')
def test_repository_deprecation_warning(self):
"""Old formats give a warning"""
- # the warning's normally off for testing but we reenable it
- repository._deprecation_warning_done = False
- try:
- os.mkdir('foo')
- bzrdir.BzrDirFormat5().initialize('foo')
- out, err = self.run_bzr("status foo")
- self.assertContainsRe(self._get_log(keep_log_file=True),
- "bzr upgrade")
- finally:
- repository._deprecation_warning_done = True
+ self.make_obsolete_repo('foo')
+ self.enable_deprecation_warning()
+ out, err = self.run_bzr('status', working_dir='foo')
+ self.check_warning(True)
+
+ def test_repository_deprecation_warning_suppressed_global(self):
+ """Old formats give a warning"""
+ conf = config.GlobalConfig()
+ conf.set_user_option('suppress_warnings', 'format_deprecation')
+ self.make_obsolete_repo('foo')
+ self.enable_deprecation_warning()
+ out, err = self.run_bzr('status', working_dir='foo')
+ self.check_warning(False)
+
+ def test_repository_deprecation_warning_suppressed_locations(self):
+ """Old formats give a warning"""
+ self.make_obsolete_repo('foo')
+ conf = config.LocationConfig(osutils.pathjoin(self.test_dir, 'foo'))
+ conf.set_user_option('suppress_warnings', 'format_deprecation')
+ self.enable_deprecation_warning()
+ out, err = self.run_bzr('status', working_dir='foo')
+ self.check_warning(False)
+
+ def test_repository_deprecation_warning_suppressed_branch(self):
+ """Old formats give a warning"""
+ tree = self.make_obsolete_repo('foo')
+ conf = tree.branch.get_config()
+ conf.set_user_option('suppress_warnings', 'format_deprecation')
+ self.enable_deprecation_warning()
+ out, err = self.run_bzr('status', working_dir='foo')
+ self.check_warning(False)
More information about the bazaar-commits
mailing list