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
=== modified file 'NEWS'
--- NEWS 2010-01-08 03:35:09 +0000
+++ NEWS 2010-01-08 05:32:16 +0000
@@ -109,6 +109,9 @@
109 CamelCase. For the features that were more likely to be used, we added a109 CamelCase. For the features that were more likely to be used, we added a
110 deprecation thunk, but not all. (John Arbash Meinel)110 deprecation thunk, but not all. (John Arbash Meinel)
111111
112* The Branch hooks pre_change_branch_tip no longer masks exceptions raised
113 by plugins - the original exceptions are now preserved. (Robert Collins)
114
112* The Transport ``Server.tearDown`` method is now renamed to115* The Transport ``Server.tearDown`` method is now renamed to
113 ``stop_server`` and ``setUp`` to ``start_server`` for consistency with116 ``stop_server`` and ``setUp`` to ``start_server`` for consistency with
114 our normal naming pattern, and to avoid confusion with Python's117 our normal naming pattern, and to avoid confusion with Python's
115118
=== modified file 'bzrlib/branch.py'
--- bzrlib/branch.py 2009-12-17 10:01:25 +0000
+++ bzrlib/branch.py 2010-01-08 05:32:16 +0000
@@ -1103,15 +1103,7 @@
1103 params = ChangeBranchTipParams(1103 params = ChangeBranchTipParams(
1104 self, old_revno, new_revno, old_revid, new_revid)1104 self, old_revno, new_revno, old_revid, new_revid)
1105 for hook in hooks:1105 for hook in hooks:
1106 try:1106 hook(params)
1107 hook(params)
1108 except errors.TipChangeRejected:
1109 raise
1110 except Exception:
1111 exc_info = sys.exc_info()
1112 hook_name = Branch.hooks.get_hook_name(hook)
1113 raise errors.HookFailed(
1114 'pre_change_branch_tip', hook_name, exc_info)
11151107
1116 @needs_write_lock1108 @needs_write_lock
1117 def update(self):1109 def update(self):
11181110
=== modified file 'bzrlib/errors.py'
--- bzrlib/errors.py 2009-12-25 13:47:23 +0000
+++ bzrlib/errors.py 2010-01-08 05:32:16 +0000
@@ -2942,12 +2942,17 @@
2942class HookFailed(BzrError):2942class HookFailed(BzrError):
2943 """Raised when a pre_change_branch_tip hook function fails anything other2943 """Raised when a pre_change_branch_tip hook function fails anything other
2944 than TipChangeRejected.2944 than TipChangeRejected.
2945
2946 Note that this exception is no longer raised, and the import is only left
2947 to be nice to code which might catch it in a plugin.
2945 """2948 """
29462949
2947 _fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"2950 _fmt = ("Hook '%(hook_name)s' during %(hook_stage)s failed:\n"
2948 "%(traceback_text)s%(exc_value)s")2951 "%(traceback_text)s%(exc_value)s")
29492952
2950 def __init__(self, hook_stage, hook_name, exc_info):2953 def __init__(self, hook_stage, hook_name, exc_info):
2954 warn("BzrError HookFailed has been deprecated as of bzrlib 2.1.",
2955 DeprecationWarning)
2951 import traceback2956 import traceback
2952 self.hook_stage = hook_stage2957 self.hook_stage = hook_stage
2953 self.hook_name = hook_name2958 self.hook_name = hook_name
29542959
=== modified file 'bzrlib/tests/per_branch/test_hooks.py'
--- bzrlib/tests/per_branch/test_hooks.py 2009-03-23 14:59:43 +0000
+++ bzrlib/tests/per_branch/test_hooks.py 2010-01-08 05:32:16 +0000
@@ -208,10 +208,7 @@
208 branch.set_last_revision_info(0, NULL_REVISION)208 branch.set_last_revision_info(0, NULL_REVISION)
209209
210 def test_hook_failure_prevents_change(self):210 def test_hook_failure_prevents_change(self):
211 """If a hook raises an exception, the change does not take effect.211 """If a hook raises an exception, the change does not take effect."""
212
213 Also, a HookFailed exception will be raised.
214 """
215 branch = self.make_branch_with_revision_ids(212 branch = self.make_branch_with_revision_ids(
216 'one-\xc2\xb5', 'two-\xc2\xb5')213 'one-\xc2\xb5', 'two-\xc2\xb5')
217 class PearShapedError(Exception):214 class PearShapedError(Exception):
@@ -221,8 +218,7 @@
221 Branch.hooks.install_named_hook(218 Branch.hooks.install_named_hook(
222 'pre_change_branch_tip', hook_that_raises, None)219 'pre_change_branch_tip', hook_that_raises, None)
223 hook_failed_exc = self.assertRaises(220 hook_failed_exc = self.assertRaises(
224 HookFailed, branch.set_last_revision_info, 0, NULL_REVISION)221 PearShapedError, branch.set_last_revision_info, 0, NULL_REVISION)
225 self.assertIsInstance(hook_failed_exc.exc_value, PearShapedError)
226 # The revision info is unchanged.222 # The revision info is unchanged.
227 self.assertEqual((2, 'two-\xc2\xb5'), branch.last_revision_info())223 self.assertEqual((2, 'two-\xc2\xb5'), branch.last_revision_info())
228224