~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Robert Collins
  • Date: 2007-03-25 08:59:56 UTC
  • mto: (2376.3.1 integration)
  • mto: This revision was merged to the branch mainline in revision 2401.
  • Revision ID: robertc@robertcollins.net-20070325085956-my8jv7cifqzyltyz
New SmartServer hooks facility. There are two initial hooks documented
in bzrlib.transport.smart.SmartServerHooks. The two initial hooks allow
plugins to execute code upon server startup and shutdown.
(Robert Collins).

SmartServer in standalone mode will now close its listening socket
when it stops, rather than waiting for garbage collection. This primarily
fixes test suite hangs when a test tries to connect to a shutdown server.
It may also help improve behaviour when dealing with a server running
on a specific port (rather than dynamically assigned ports).
(Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
                           NotBranchError, UninitializableFormat,
55
55
                           UnlistableStore, UnlistableBranch,
56
56
                           )
 
57
from bzrlib.hooks import Hooks
57
58
from bzrlib.symbol_versioning import (deprecated_function,
58
59
                                      deprecated_method,
59
60
                                      DEPRECATED_PARAMETER,
884
885
            control_files.unlock()
885
886
 
886
887
 
887
 
class BranchHooks(dict):
 
888
class BranchHooks(Hooks):
888
889
    """A dictionary mapping hook name to a list of callables for branch hooks.
889
890
    
890
891
    e.g. ['set_rh'] Is the list of items to be called when the
897
898
        These are all empty initially, because by default nothing should get
898
899
        notified.
899
900
        """
900
 
        dict.__init__(self)
 
901
        Hooks.__init__(self)
901
902
        # Introduced in 0.15:
902
903
        # invoked whenever the revision history has been set
903
904
        # with set_revision_history. The api signature is
936
937
        # and an empty branch recieves new_revno of 0, new_revid of None.
937
938
        self['post_uncommit'] = []
938
939
 
939
 
    def install_hook(self, hook_name, a_callable):
940
 
        """Install a_callable in to the hook hook_name.
941
 
 
942
 
        :param hook_name: A hook name. See the __init__ method of BranchHooks
943
 
            for the complete list of hooks.
944
 
        :param a_callable: The callable to be invoked when the hook triggers.
945
 
            The exact signature will depend on the hook - see the __init__ 
946
 
            method of BranchHooks for details on each hook.
947
 
        """
948
 
        try:
949
 
            self[hook_name].append(a_callable)
950
 
        except KeyError:
951
 
            raise errors.UnknownHook('branch', hook_name)
952
 
 
953
940
 
954
941
# install the default hooks into the Branch class.
955
942
Branch.hooks = BranchHooks()