Rev 4944: (robertc) The Branch hooks pre_change_branch_tip no longer masks in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Fri Jan 8 07:18:08 GMT 2010


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

------------------------------------------------------------
revno: 4944 [merge]
revision-id: pqm at pqm.ubuntu.com-20100108071807-vmk4kojiz0oqsyl5
parent: pqm at pqm.ubuntu.com-20100108033509-5dp440ermqsavlhr
parent: robertc at robertcollins.net-20100108063305-qxgq2t7prgp0op1j
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2010-01-08 07:18:07 +0000
message:
  (robertc) The Branch hooks pre_change_branch_tip no longer masks
  	exceptions raised by plugins - the original exceptions are now
  	pre^Crved. (Robert Collins)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
  bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
  bzrlib/tests/per_branch/test_hooks.py test_hooks.py-20070129154855-blhpwxmvjs07waei-1
  bzrlib/tests/test_errors.py    test_errors.py-20060210110251-41aba2deddf936a8
=== modified file 'NEWS'
--- a/NEWS	2010-01-08 03:35:09 +0000
+++ b/NEWS	2010-01-08 05:28:17 +0000
@@ -109,6 +109,9 @@
   CamelCase. For the features that were more likely to be used, we added a
   deprecation thunk, but not all. (John Arbash Meinel)
 
+* The Branch hooks pre_change_branch_tip no longer masks exceptions raised
+  by plugins - the original exceptions are now preserved. (Robert Collins)
+
 * The Transport ``Server.tearDown`` method is now renamed to
   ``stop_server`` and ``setUp`` to ``start_server`` for consistency with
   our normal naming pattern, and to avoid confusion with Python's

=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2009-12-17 10:01:25 +0000
+++ b/bzrlib/branch.py	2010-01-08 05:28:17 +0000
@@ -1103,15 +1103,7 @@
         params = ChangeBranchTipParams(
             self, old_revno, new_revno, old_revid, new_revid)
         for hook in hooks:
-            try:
-                hook(params)
-            except errors.TipChangeRejected:
-                raise
-            except Exception:
-                exc_info = sys.exc_info()
-                hook_name = Branch.hooks.get_hook_name(hook)
-                raise errors.HookFailed(
-                    'pre_change_branch_tip', hook_name, exc_info)
+            hook(params)
 
     @needs_write_lock
     def update(self):

=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py	2009-12-25 13:47:23 +0000
+++ b/bzrlib/errors.py	2010-01-08 06:33:05 +0000
@@ -1247,8 +1247,8 @@
 class AmbiguousBase(BzrError):
 
     def __init__(self, bases):
-        warn("BzrError AmbiguousBase has been deprecated as of bzrlib 0.8.",
-                DeprecationWarning)
+        symbol_versioning.warn("BzrError AmbiguousBase has been deprecated "
+            "as of bzrlib 0.8.", DeprecationWarning, stacklevel=2)
         msg = ("The correct base is unclear, because %s are all equally close"
                 % ", ".join(bases))
         BzrError.__init__(self, msg)
@@ -2942,12 +2942,18 @@
 class HookFailed(BzrError):
     """Raised when a pre_change_branch_tip hook function fails anything other
     than TipChangeRejected.
+
+    Note that this exception is no longer raised, and the import is only left
+    to be nice to code which might catch it in a plugin.
     """
 
     _fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
             "%(traceback_text)s%(exc_value)s")
 
-    def __init__(self, hook_stage, hook_name, exc_info):
+    def __init__(self, hook_stage, hook_name, exc_info, warn=True):
+        if warn:
+            symbol_versioning.warn("BzrError HookFailed has been deprecated "
+                "as of bzrlib 2.1.", DeprecationWarning, stacklevel=2)
         import traceback
         self.hook_stage = hook_stage
         self.hook_name = hook_name

=== modified file 'bzrlib/tests/per_branch/test_hooks.py'
--- a/bzrlib/tests/per_branch/test_hooks.py	2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/per_branch/test_hooks.py	2010-01-08 05:28:17 +0000
@@ -208,10 +208,7 @@
         branch.set_last_revision_info(0, NULL_REVISION)
 
     def test_hook_failure_prevents_change(self):
-        """If a hook raises an exception, the change does not take effect.
-
-        Also, a HookFailed exception will be raised.
-        """
+        """If a hook raises an exception, the change does not take effect."""
         branch = self.make_branch_with_revision_ids(
             'one-\xc2\xb5', 'two-\xc2\xb5')
         class PearShapedError(Exception):
@@ -221,8 +218,7 @@
         Branch.hooks.install_named_hook(
             'pre_change_branch_tip', hook_that_raises, None)
         hook_failed_exc = self.assertRaises(
-            HookFailed, branch.set_last_revision_info, 0, NULL_REVISION)
-        self.assertIsInstance(hook_failed_exc.exc_value, PearShapedError)
+            PearShapedError, branch.set_last_revision_info, 0, NULL_REVISION)
         # The revision info is unchanged.
         self.assertEqual((2, 'two-\xc2\xb5'), branch.last_revision_info())
 

=== modified file 'bzrlib/tests/test_errors.py'
--- a/bzrlib/tests/test_errors.py	2009-08-21 02:37:18 +0000
+++ b/bzrlib/tests/test_errors.py	2010-01-08 06:33:05 +0000
@@ -542,7 +542,7 @@
             1/0
         except ZeroDivisionError:
             exc_info = sys.exc_info()
-        err = errors.HookFailed('hook stage', 'hook name', exc_info)
+        err = errors.HookFailed('hook stage', 'hook name', exc_info, warn=False)
         self.assertStartsWith(
             str(err), 'Hook \'hook name\' during hook stage failed:\n')
         self.assertEndsWith(




More information about the bazaar-commits mailing list