Rev 6332: allow lazily registered hooks to have their names appear in "bzr in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/
Patch Queue Manager
pqm at pqm.ubuntu.com
Thu Dec 1 02:38:46 UTC 2011
At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 6332 [merge]
revision-id: pqm at pqm.ubuntu.com-20111201023846-zw38oqm28xr25trs
parent: pqm at pqm.ubuntu.com-20111130082957-wkkb5rcx24hrzn4x
parent: mbp at canonical.com-20111201014449-vf3lyhjq4ueq3uk4
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2011-12-01 02:38:46 +0000
message:
allow lazily registered hooks to have their names appear in "bzr
hooks" (bug 894609)
modified:
bzrlib/hooks.py hooks.py-20070325015548-ix4np2q0kd8452au-1
bzrlib/tests/blackbox/test_hooks.py test_hooks.py-20080308163236-xljgf9j41hik1x21-1
doc/en/release-notes/bzr-2.5.txt bzr2.5.txt-20110708125756-587p0hpw7oke4h05-1
=== modified file 'bzrlib/hooks.py'
--- a/bzrlib/hooks.py 2011-10-11 10:21:35 +0000
+++ b/bzrlib/hooks.py 2011-11-28 18:57:59 +0000
@@ -127,6 +127,7 @@
"""
dict.__init__(self)
self._callable_names = {}
+ self._lazy_callable_names = {}
self._module = module
self._member_name = member_name
@@ -196,7 +197,15 @@
the code names are rarely meaningful for end users and this is not
intended for debugging.
"""
- return self._callable_names.get(a_callable, "No hook name")
+ name = self._callable_names.get(a_callable, None)
+ if name is None and a_callable is not None:
+ name = self._lazy_callable_names.get((a_callable.__module__,
+ a_callable.__name__),
+ None)
+ if name is None:
+ return 'No hook name'
+ return name
+
def install_named_hook_lazy(self, hook_name, callable_module,
callable_member, name):
@@ -221,6 +230,8 @@
self)
else:
hook_lazy(callable_module, callable_member, name)
+ if name is not None:
+ self.name_hook_lazy(callable_module, callable_member, name)
def install_named_hook(self, hook_name, a_callable, name):
"""Install a_callable in to the hook hook_name, and label it name.
@@ -266,6 +277,10 @@
"""Associate name with a_callable to show users what is running."""
self._callable_names[a_callable] = name
+ def name_hook_lazy(self, callable_module, callable_member, callable_name):
+ self._lazy_callable_names[(callable_module, callable_member)]= \
+ callable_name
+
class HookPoint(object):
"""A single hook that clients can register to be called back when it fires.
=== modified file 'bzrlib/tests/blackbox/test_hooks.py'
--- a/bzrlib/tests/blackbox/test_hooks.py 2009-03-23 14:59:43 +0000
+++ b/bzrlib/tests/blackbox/test_hooks.py 2011-11-28 18:57:59 +0000
@@ -19,6 +19,8 @@
from bzrlib.branch import Branch
from bzrlib.tests import TestCaseWithTransport
+def _foo_hook():
+ pass
class TestHooks(TestCaseWithTransport):
@@ -51,3 +53,23 @@
def test_hooks_no_branch(self):
self.run_bzr('hooks')
+
+ def test_hooks_lazy_with_unnamed_hook(self):
+ self.make_branch('.')
+ def foo(): return
+ Branch.hooks.install_named_hook_lazy('set_rh',
+ 'bzrlib.tests.blackbox.test_hooks',
+ '_foo_hook',
+ None)
+ out, err = self.run_bzr('hooks')
+ self._check_hooks_output(out, {'set_rh': ["No hook name"]})
+
+ def test_hooks_lazy_with_named_hook(self):
+ self.make_branch('.')
+ def foo(): return
+ Branch.hooks.install_named_hook_lazy('set_rh',
+ 'bzrlib.tests.blackbox.test_hooks',
+ '_foo_hook',
+ 'hook has a name')
+ out, err = self.run_bzr('hooks')
+ self._check_hooks_output(out, {'set_rh': ["hook has a name"]})
=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt 2011-11-29 16:27:56 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt 2011-12-01 01:44:49 +0000
@@ -86,6 +86,10 @@
for _CompatabilityThunkFeature based test features.
(Vincent Ladeuil, #897718)
+* Provide names for lazily registered hooks.
+ (Neil Martinsen-Burrell, #894609)
+
+
* Raise BadIndexKey exception in btree_index when a key is too large, fixing
an infinite recursion issue. (Shannon Weyrick, #720853)
More information about the bazaar-commits
mailing list