~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/hooks.py

(jelmer) Reduce the number of connections made during "bzr branch
 --stacked". (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
 
17
 
17
18
"""Support for plugin hooking logic."""
18
19
 
19
 
from __future__ import absolute_import
20
 
 
21
20
from bzrlib import (
22
21
    registry,
23
22
    symbol_versioning,
128
127
        """
129
128
        dict.__init__(self)
130
129
        self._callable_names = {}
131
 
        self._lazy_callable_names = {}
132
130
        self._module = module
133
131
        self._member_name = member_name
134
132
 
198
196
        the code names are rarely meaningful for end users and this is not
199
197
        intended for debugging.
200
198
        """
201
 
        name = self._callable_names.get(a_callable, None)
202
 
        if name is None and a_callable is not None:
203
 
            name = self._lazy_callable_names.get((a_callable.__module__,
204
 
                                                  a_callable.__name__),
205
 
                                                 None)
206
 
        if name is None:
207
 
            return 'No hook name'
208
 
        return name
209
 
 
 
199
        return self._callable_names.get(a_callable, "No hook name")
210
200
 
211
201
    def install_named_hook_lazy(self, hook_name, callable_module,
212
202
        callable_member, name):
231
221
                self)
232
222
        else:
233
223
            hook_lazy(callable_module, callable_member, name)
234
 
        if name is not None:
235
 
            self.name_hook_lazy(callable_module, callable_member, name)
236
224
 
237
225
    def install_named_hook(self, hook_name, a_callable, name):
238
226
        """Install a_callable in to the hook hook_name, and label it name.
278
266
        """Associate name with a_callable to show users what is running."""
279
267
        self._callable_names[a_callable] = name
280
268
 
281
 
    def name_hook_lazy(self, callable_module, callable_member, callable_name):
282
 
        self._lazy_callable_names[(callable_module, callable_member)]= \
283
 
            callable_name
284
 
 
285
269
 
286
270
class HookPoint(object):
287
271
    """A single hook that clients can register to be called back when it fires.