~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Robert Collins
  • Date: 2007-01-30 11:52:30 UTC
  • mto: This revision was merged to the branch mainline in revision 2246.
  • Revision ID: robertc@robertcollins.net-20070130115230-2052dzn5xo9h6o07
Add install_hook to the BranchHooks class as the official means for installing a hook.

Show diffs side-by-side

added added

removed removed

Lines of Context:
631
631
        return checkout.create_workingtree(revision_id)
632
632
 
633
633
 
634
 
class BranchHooks(dict):
635
 
    """A dictionary mapping hook name to a list of callables for branch hooks.
636
 
    
637
 
    e.g. ['set_rh'] Is the list of items to be called when the
638
 
    set_revision_history function is invoked.
639
 
    """
640
 
 
641
 
    def __init__(self):
642
 
        """Create the default hooks.
643
 
 
644
 
        These are all empty initially, because by default nothing should get
645
 
        notified.
646
 
        """
647
 
        dict.__init__(self)
648
 
        # invoked whenever the revision history has been set
649
 
        # with set_revision_history. The api signature is
650
 
        # (branch, revision_history), and the branch will
651
 
        # be write-locked.
652
 
        self['set_rh'] = []
653
 
 
654
 
# install the default hooks into the class.
655
 
Branch.hooks = BranchHooks()
656
 
 
657
 
 
658
634
class BranchFormat(object):
659
635
    """An encapsulation of the initialization and open routines for a format.
660
636
 
742
718
        return self.get_format_string().rstrip()
743
719
 
744
720
 
 
721
class BranchHooks(dict):
 
722
    """A dictionary mapping hook name to a list of callables for branch hooks.
 
723
    
 
724
    e.g. ['set_rh'] Is the list of items to be called when the
 
725
    set_revision_history function is invoked.
 
726
    """
 
727
 
 
728
    def __init__(self):
 
729
        """Create the default hooks.
 
730
 
 
731
        These are all empty initially, because by default nothing should get
 
732
        notified.
 
733
        """
 
734
        dict.__init__(self)
 
735
        # invoked whenever the revision history has been set
 
736
        # with set_revision_history. The api signature is
 
737
        # (branch, revision_history), and the branch will
 
738
        # be write-locked. Introduced in 0.15.
 
739
        self['set_rh'] = []
 
740
 
 
741
    def install_hook(self, hook_name, a_callable):
 
742
        """Install a_callable in to the hook hook_name.
 
743
 
 
744
        :param hook_name: A hook name. See the __init__ method of BranchHooks
 
745
            for the complete list of hooks.
 
746
        :param a_callable: The callable to be invoked when the hook triggers.
 
747
            The exact signature will depend on the hook - see the __init__ 
 
748
            method of BranchHooks for details on each hook.
 
749
        """
 
750
        try:
 
751
            self[hook_name].append(a_callable)
 
752
        except KeyError:
 
753
            raise errors.UnknownHook('branch', hook_name)
 
754
 
 
755
 
 
756
# install the default hooks into the Branch class.
 
757
Branch.hooks = BranchHooks()
 
758
 
 
759
 
745
760
class BzrBranchFormat4(BranchFormat):
746
761
    """Bzr branch format 4.
747
762