Merge lp:~jelmer/lpreview-body/lazy-hooks into lp:lpreview-body

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: 22
Merged at revision: 22
Proposed branch: lp:~jelmer/lpreview-body/lazy-hooks
Merge into: lp:lpreview-body
Diff against target: 65 lines (+27/-16)
1 file modified
__init__.py (+27/-16)
To merge this branch: bzr merge lp:~jelmer/lpreview-body/lazy-hooks
Reviewer Review Type Date Requested Status
j.c.sackett (community) Approve
Review via email: mp+50471@code.launchpad.net

Description of the change

If the current version of bzr supports it, lazily install the hooks.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

The right functions have now landed in bzr.dev.

Revision history for this message
j.c.sackett (jcsackett) wrote :

Nice and straightforward. Looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '__init__.py'
2--- __init__.py 2010-08-04 10:58:33 +0000
3+++ __init__.py 2011-02-19 21:07:17 +0000
4@@ -16,8 +16,7 @@
5
6 """Provide review message bodies for proposed merges to Launchpad itself."""
7
8-from bzrlib import commands, merge_directive
9-
10+from bzrlib import commands
11
12 def shim(params):
13 from body_callback import body_callback
14@@ -31,25 +30,37 @@
15 hook_params['old_body'])
16
17
18-if getattr(merge_directive.MergeDirective, 'hooks', None) is not None:
19- merge_directive.MergeDirective.hooks.install_named_hook(
20- 'merge_request_body',
21- shim, 'Generate a message body for Launchpad merge requests.'
22- )
23 try:
24- from bzrlib.plugins.launchpad import lp_propose
25-except ImportError:
26- pass
27+ from bzrlib.hooks import install_lazy_named_hook
28+except ImportError: # bzr < 2.4
29+ from bzrlib import merge_directive
30+ if getattr(merge_directive.MergeDirective, 'hooks', None) is not None:
31+ merge_directive.MergeDirective.hooks.install_named_hook(
32+ 'merge_request_body',
33+ shim, 'Generate a message body for Launchpad merge requests.'
34+ )
35+ try:
36+ from bzrlib.plugins.launchpad import lp_propose
37+ except ImportError:
38+ pass
39+ else:
40+ lp_propose.Proposer.hooks.install_named_hook(
41+ 'merge_proposal_body',
42+ proposer_callback,
43+ 'Generate a message body for Launchpad merge requests.'
44+ )
45 else:
46- lp_propose.Proposer.hooks.install_named_hook(
47- 'merge_proposal_body',
48- proposer_callback,
49- 'Generate a message body for Launchpad merge requests.'
50- )
51+ install_lazy_named_hook(
52+ "bzrlib.merge_directive", "MergeDirective.hooks",
53+ 'merge_request_body',
54+ shim, 'Generate a message body for Launchpad merge requests.')
55+ install_lazy_named_hook(
56+ "bzrlib.plugins.launcjpad.lp_propose", "Proposer.hooks",
57+ 'merge_proposal_body', proposer_callback,
58+ 'Generate a message body for Launchpad merge requests.')
59
60
61 commands.plugin_cmds.register_lazy(
62 'cmd_qa_ready', [], 'bzrlib.plugins.lpreview_body.qa_ready')
63-
64 commands.plugin_cmds.register_lazy(
65 'cmd_lp_link_bug', [], 'bzrlib.plugins.lpreview_body.link_bug')

Subscribers

People subscribed via source and target branches

to all changes: