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

Proposed by Jelmer Vernooij
Status: Merged
Approved by: John A Meinel
Approved revision: 48
Merged at revision: 48
Proposed branch: lp:~jelmer/bzr-dbus/lazy-hooks
Merge into: lp:bzr-dbus
Diff against target: 89 lines (+41/-22)
2 files modified
__init__.py (+41/-3)
hook.py (+0/-19)
To merge this branch: bzr merge lp:~jelmer/bzr-dbus/lazy-hooks
Reviewer Review Type Date Requested Status
John A Meinel Approve
Review via email: mp+55537@code.launchpad.net

Commit message

Lazily register hooks if possible.

Description of the change

Lazily register hooks if supported by the version of bzrlib used.

This avoids loading of the smart server unless it's actually used.

To post a comment you must log in.
Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 3/31/2011 5:03 PM, Jelmer Vernooij wrote:
> Jelmer Vernooij has proposed merging lp:~jelmer/bzr-dbus/lazy-hooks into lp:bzr-dbus.
>
> Requested reviews:
> Bazaar Developers (bzr)
>
> For more details, see:
> https://code.launchpad.net/~jelmer/bzr-dbus/lazy-hooks/+merge/55537
>
> Lazily register hooks if supported by the version of bzrlib used.
>
> This avoids loading of the smart server unless it's actually used.

 merge: approve

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk2UmPsACgkQJdeBCYSNAAOTFwCgs22JedZ6mZOPR1T5anDpf18r
1E8AoL+E71X2zB+Ws50ZmBIton8PfDyW
=8x7X
-----END PGP SIGNATURE-----

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-02-11 17:55:04 +0000
3+++ __init__.py 2011-03-30 13:25:38 +0000
4@@ -66,14 +66,52 @@
5
6 from bzrlib import commands
7
8-from bzrlib.plugins.dbus.hook import install_hooks
9-
10-
11 def test_suite():
12 import tests
13 return tests.test_suite()
14
15
16+def install_hooks():
17+ """Install the dbus hooks into bzrlib."""
18+ try:
19+ from bzrlib.hooks import install_lazy_named_hook
20+ except ImportError: # bzr < 2.4
21+ from bzrlib.branch import Branch
22+ from bzrlib.smart.server import SmartTCPServer
23+ from bzrlib.plugins.dbus.hook import (
24+ on_post_change_branch_tip,
25+ on_post_commit,
26+ on_server_start,
27+ on_server_stop,
28+ )
29+ Branch.hooks.install_named_hook(
30+ 'post_change_branch_tip', on_post_change_branch_tip,
31+ 'Announcing on branch change on D-Bus')
32+ Branch.hooks.install_named_hook(
33+ 'post_commit', on_post_commit,
34+ 'Zeitgeist dataprovider')
35+ SmartTCPServer.hooks.install_named_hook(
36+ 'server_started', on_server_start,
37+ 'Registering server URL mapping')
38+ SmartTCPServer.hooks.install_named_hook(
39+ 'server_stopped', on_server_stop,
40+ 'Unregistering server mapping')
41+ else:
42+ install_lazy_named_hook("bzrlib.branch", "Branch.hooks",
43+ 'post_change_branch_tip', "bzrlib.plugins.dbus.hook",
44+ "on_post_change_branch_tip",
45+ 'Announcing on branch change on D-Bus')
46+ install_lazy_named_hook("bzrlib.branch", "Branch.hooks",
47+ 'post_commit', "bzrlib.plugins.dbus.hook",
48+ "on_post_commit", 'Zeitgeist dataprovider')
49+ install_lazy_named_hook("bzrlib.smart.server", "SmartTCPServer.hooks",
50+ 'server_started', "bzrlib.plugins.dbus.hook",
51+ "on_server_start", 'Registering server URL mapping')
52+ install_lazy_named_hook("bzrlib.smart.server", "SmartTCPServer.hooks",
53+ 'server_stopped', "bzrlib.plugins.dbus.hook",
54+ "on_server_stop", 'Unregistering server mapping')
55+
56+
57 install_hooks()
58
59
60
61=== modified file 'hook.py'
62--- hook.py 2010-06-29 23:38:25 +0000
63+++ hook.py 2011-03-30 13:25:38 +0000
64@@ -20,25 +20,6 @@
65 """System wide hooks to trigger dbus events from bzr activity."""
66
67
68-from bzrlib.branch import Branch
69-from bzrlib.smart.server import SmartTCPServer
70-
71-def install_hooks():
72- """Install the dbus hooks into bzrlib."""
73- Branch.hooks.install_named_hook(
74- 'post_change_branch_tip', on_post_change_branch_tip,
75- 'Announcing on branch change on D-Bus')
76- Branch.hooks.install_named_hook(
77- 'post_commit', on_post_commit,
78- 'Zeitgeist dataprovider')
79- SmartTCPServer.hooks.install_named_hook(
80- 'server_started', on_server_start,
81- 'Registering server URL mapping')
82- SmartTCPServer.hooks.install_named_hook(
83- 'server_stopped', on_server_stop,
84- 'Unregistering server mapping')
85-
86-
87 def get_activity():
88 import activity
89 import dbus

Subscribers

People subscribed via source and target branches