Merge lp:~jelmer/bzr-builddeb/lazy-hooks into lp:bzr-builddeb

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: 521
Merged at revision: 549
Proposed branch: lp:~jelmer/bzr-builddeb/lazy-hooks
Merge into: lp:bzr-builddeb
Diff against target: 111 lines (+42/-29)
1 file modified
__init__.py (+42/-29)
To merge this branch: bzr merge lp:~jelmer/bzr-builddeb/lazy-hooks
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+50470@code.launchpad.net

Description of the change

Use the new install_lazy_named_hook() call in bzr 2.4 to register hooks.

This avoids loading bzrlib.msgeditor and bzrlib.merge every time bzr
gets invoked.

To post a comment you must log in.
Revision history for this message
James Westby (james-w) :
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 2011-02-06 12:45:53 +0000
3+++ __init__.py 2011-02-19 20:52:17 +0000
4@@ -26,14 +26,7 @@
5 import os
6
7 import bzrlib
8-from bzrlib import (
9- branch as _mod_branch,
10- errors,
11- merge,
12- msgeditor,
13- )
14 from bzrlib.commands import plugin_cmds
15-from bzrlib.config import config_dir
16 from bzrlib.directory_service import directories
17
18 from info import (
19@@ -41,19 +34,6 @@
20 )
21
22
23-if getattr(merge, 'ConfigurableFileMerger', None) is None:
24- raise ImportError(
25- 'need at least bzr 2.1.0rc2 (you use %r)', bzrlib.version_info)
26-else:
27- def changelog_merge_hook_factory(merger):
28- from bzrlib.plugins.builddeb import merge_changelog
29- return merge_changelog.ChangeLogFileMerge(merger)
30-
31- merge.Merger.hooks.install_named_hook(
32- 'merge_file_content', changelog_merge_hook_factory,
33- 'Debian Changelog file merge')
34-
35-
36 commands = {
37 "bd_do": [],
38 "builddeb": ["bd"],
39@@ -72,6 +52,7 @@
40 builddeb_dir = '.bzr-builddeb'
41 default_conf = os.path.join(builddeb_dir, 'default.conf')
42 def global_conf():
43+ from bzrlib.config import config_dir
44 return os.path.join(config_dir(), 'builddeb.conf')
45 local_conf = os.path.join(builddeb_dir, 'local.conf')
46
47@@ -128,10 +109,9 @@
48 return "".join(changes)
49
50
51-msgeditor.hooks.install_named_hook("commit_message_template",
52- debian_changelog_commit_message,
53- "Use changes documented in debian/changelog to suggest "
54- "the commit message")
55+def changelog_merge_hook_factory(merger):
56+ from bzrlib.plugins.builddeb import merge_changelog
57+ return merge_changelog.ChangeLogFileMerge(merger)
58
59
60 def debian_tag_name(branch, revid):
61@@ -158,12 +138,45 @@
62
63
64 try:
65- _mod_branch.Branch.hooks.install_named_hook("automatic_tag_name",
66- debian_tag_name,
67+ from bzrlib.hooks import install_lazy_named_hook
68+except ImportError: # Compatibility with bzr < 2.4
69+ from bzrlib import (
70+ branch as _mod_branch,
71+ errors,
72+ merge,
73+ msgeditor,
74+ )
75+ msgeditor.hooks.install_named_hook("commit_message_template",
76+ debian_changelog_commit_message,
77+ "Use changes documented in debian/changelog to suggest "
78+ "the commit message")
79+ if getattr(merge, 'ConfigurableFileMerger', None) is None:
80+ raise ImportError(
81+ 'need at least bzr 2.1.0rc2 (you use %r)', bzrlib.version_info)
82+ else:
83+ merge.Merger.hooks.install_named_hook(
84+ 'merge_file_content', changelog_merge_hook_factory,
85+ 'Debian Changelog file merge')
86+ try:
87+ _mod_branch.Branch.hooks.install_named_hook("automatic_tag_name",
88+ debian_tag_name,
89+ "Automatically determine tag names from Debian version")
90+ except errors.UnknownHook:
91+ pass # bzr < 2.2 doesn't have this hook.
92+else:
93+ install_lazy_named_hook(
94+ "bzrlib.msgeditor", "hooks", "commit_message_template",
95+ debian_changelog_commit_message,
96+ "Use changes documented in debian/changelog to suggest "
97+ "the commit message")
98+ install_lazy_named_hook(
99+ "bzrlib.merge", "Merger.hooks",
100+ 'merge_file_content', changelog_merge_hook_factory,
101+ 'Debian Changelog file merge')
102+ install_lazy_named_hook(
103+ "bzrlib.branch", "Branch.hooks",
104+ "automatic_tag_name", debian_tag_name,
105 "Automatically determine tag names from Debian version")
106-except errors.UnknownHook:
107- pass # bzr < 2.2 doesn't have this hook.
108-
109
110 try:
111 from bzrlib.revisionspec import revspec_registry

Subscribers

People subscribed via source and target branches