35
36
known_hooks.register_lazy(('bzrlib.commands', 'Command.hooks'),
36
37
'bzrlib.commands', 'CommandHooks')
38
known_hooks.register_lazy(('bzrlib.lock', 'Lock.hooks'), 'bzrlib.lock',
37
40
known_hooks.register_lazy(('bzrlib.mutabletree', 'MutableTree.hooks'),
38
41
'bzrlib.mutabletree', 'MutableTreeHooks')
39
42
known_hooks.register_lazy(('bzrlib.smart.client', '_SmartClient.hooks'),
112
115
strings.append(hook_name)
113
strings.append("-" * len(hook_name))
116
strings.append("~" * len(hook_name))
114
117
strings.append("")
115
118
strings.append("An old-style hook. For documentation see the __init__ "
116
119
"method of '%s'\n" % (name,))
220
223
strings.append('')
221
224
return '\n'.join(strings)
226
def __eq__(self, other):
227
return (type(other) == type(self) and
228
other.__dict__ == self.__dict__)
223
230
def hook(self, callback, callback_label):
224
231
"""Register a callback to be called when this HookPoint fires.
230
237
self._callbacks.append(callback)
231
self._callback_names[callback] = callback_label
238
if callback_label is not None:
239
self._callback_names[callback] = callback_label
233
241
def __iter__(self):
234
242
return iter(self._callbacks)
247
255
strings[-1] = ")"
248
256
strings.append("]>")
249
257
return ''.join(strings)
268
A hook of type *xxx* of class *yyy* needs to be registered using::
270
yyy.hooks.install_named_hook("xxx", ...)
272
See `Using hooks`_ in the User Guide for examples.
274
.. _Using hooks: ../user-guide/index.html#using-hooks
276
The class that contains each hook is given before the hooks it supplies. For
277
instance, BranchHooks as the class is the hooks class for
278
`bzrlib.branch.Branch.hooks`.
280
Each description also indicates whether the hook runs on the client (the
281
machine where bzr was invoked) or the server (the machine addressed by
282
the branch URL). These may be, but are not necessarily, the same machine.
284
Plugins (including hooks) are run on the server if all of these is true:
286
* The connection is via a smart server (accessed with a URL starting with
287
"bzr://", "bzr+ssh://" or "bzr+http://", or accessed via a "http://"
288
URL when a smart server is available via HTTP).
290
* The hook is either server specific or part of general infrastructure rather
291
than client specific code (such as commit).
295
def hooks_help_text(topic):
296
segments = [_help_prefix]
297
for hook_key in sorted(known_hooks.keys()):
298
hooks = known_hooks_key_to_object(hook_key)
299
segments.append(hooks.docs())
300
return '\n'.join(segments)