Merge lp:~lifeless/bzr/hooks into lp:bzr

Proposed by Robert Collins
Status: Merged
Approved by: Andrew Bennetts
Approved revision: not available
Merged at revision: not available
Proposed branch: lp:~lifeless/bzr/hooks
Merge into: lp:bzr
Diff against target: 81 lines (+11/-15)
4 files modified
NEWS (+3/-0)
bzrlib/branch.py (+1/-9)
bzrlib/errors.py (+5/-0)
bzrlib/tests/per_branch/test_hooks.py (+2/-6)
To merge this branch: bzr merge lp:~lifeless/bzr/hooks
Reviewer Review Type Date Requested Status
Andrew Bennetts Approve
Review via email: mp+17005@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote :

This cleans up some unnecessary code in one of the branch hooks.

Revision history for this message
Andrew Bennetts (spiv) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2010-01-08 03:35:09 +0000
3+++ NEWS 2010-01-08 05:32:16 +0000
4@@ -109,6 +109,9 @@
5 CamelCase. For the features that were more likely to be used, we added a
6 deprecation thunk, but not all. (John Arbash Meinel)
7
8+* The Branch hooks pre_change_branch_tip no longer masks exceptions raised
9+ by plugins - the original exceptions are now preserved. (Robert Collins)
10+
11 * The Transport ``Server.tearDown`` method is now renamed to
12 ``stop_server`` and ``setUp`` to ``start_server`` for consistency with
13 our normal naming pattern, and to avoid confusion with Python's
14
15=== modified file 'bzrlib/branch.py'
16--- bzrlib/branch.py 2009-12-17 10:01:25 +0000
17+++ bzrlib/branch.py 2010-01-08 05:32:16 +0000
18@@ -1103,15 +1103,7 @@
19 params = ChangeBranchTipParams(
20 self, old_revno, new_revno, old_revid, new_revid)
21 for hook in hooks:
22- try:
23- hook(params)
24- except errors.TipChangeRejected:
25- raise
26- except Exception:
27- exc_info = sys.exc_info()
28- hook_name = Branch.hooks.get_hook_name(hook)
29- raise errors.HookFailed(
30- 'pre_change_branch_tip', hook_name, exc_info)
31+ hook(params)
32
33 @needs_write_lock
34 def update(self):
35
36=== modified file 'bzrlib/errors.py'
37--- bzrlib/errors.py 2009-12-25 13:47:23 +0000
38+++ bzrlib/errors.py 2010-01-08 05:32:16 +0000
39@@ -2942,12 +2942,17 @@
40 class HookFailed(BzrError):
41 """Raised when a pre_change_branch_tip hook function fails anything other
42 than TipChangeRejected.
43+
44+ Note that this exception is no longer raised, and the import is only left
45+ to be nice to code which might catch it in a plugin.
46 """
47
48 _fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
49 "%(traceback_text)s%(exc_value)s")
50
51 def __init__(self, hook_stage, hook_name, exc_info):
52+ warn("BzrError HookFailed has been deprecated as of bzrlib 2.1.",
53+ DeprecationWarning)
54 import traceback
55 self.hook_stage = hook_stage
56 self.hook_name = hook_name
57
58=== modified file 'bzrlib/tests/per_branch/test_hooks.py'
59--- bzrlib/tests/per_branch/test_hooks.py 2009-03-23 14:59:43 +0000
60+++ bzrlib/tests/per_branch/test_hooks.py 2010-01-08 05:32:16 +0000
61@@ -208,10 +208,7 @@
62 branch.set_last_revision_info(0, NULL_REVISION)
63
64 def test_hook_failure_prevents_change(self):
65- """If a hook raises an exception, the change does not take effect.
66-
67- Also, a HookFailed exception will be raised.
68- """
69+ """If a hook raises an exception, the change does not take effect."""
70 branch = self.make_branch_with_revision_ids(
71 'one-\xc2\xb5', 'two-\xc2\xb5')
72 class PearShapedError(Exception):
73@@ -221,8 +218,7 @@
74 Branch.hooks.install_named_hook(
75 'pre_change_branch_tip', hook_that_raises, None)
76 hook_failed_exc = self.assertRaises(
77- HookFailed, branch.set_last_revision_info, 0, NULL_REVISION)
78- self.assertIsInstance(hook_failed_exc.exc_value, PearShapedError)
79+ PearShapedError, branch.set_last_revision_info, 0, NULL_REVISION)
80 # The revision info is unchanged.
81 self.assertEqual((2, 'two-\xc2\xb5'), branch.last_revision_info())
82