~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

Add pre_change_branch_tip hook. (Andrew Bennetts)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1109
1109
        # local is the local branch or None, master is the target branch,
1110
1110
        # and an empty branch recieves new_revno of 0, new_revid of None.
1111
1111
        self['post_uncommit'] = []
 
1112
        # Introduced in 1.6
 
1113
        # Invoked before the tip of a branch changes.
 
1114
        # the api signature is
 
1115
        # (params) where params is a ChangeBranchTipParams with the members
 
1116
        # (branch, old_revno, new_revno, old_revid, new_revid)
 
1117
        self['pre_change_branch_tip'] = []
1112
1118
        # Introduced in 1.4
1113
1119
        # Invoked after the tip of a branch changes.
1114
1120
        # the api signature is
1150
1156
        self.old_revid = old_revid
1151
1157
        self.new_revid = new_revid
1152
1158
 
 
1159
    def __eq__(self, other):
 
1160
        return self.__dict__ == other.__dict__
 
1161
    
 
1162
    def __repr__(self):
 
1163
        return "<%s of %s from (%s, %s) to (%s, %s)>" % (
 
1164
            self.__class__.__name__, self.branch, 
 
1165
            self.old_revno, self.old_revid, self.new_revno, self.new_revid)
 
1166
 
1153
1167
 
1154
1168
class BzrBranchFormat4(BranchFormat):
1155
1169
    """Bzr branch format 4.
1512
1526
        for hook in Branch.hooks['set_rh']:
1513
1527
            hook(self, rev_history)
1514
1528
 
 
1529
    def _run_pre_change_branch_tip_hooks(self, new_revno, new_revid):
 
1530
        """Run the pre_change_branch_tip hooks."""
 
1531
        hooks = Branch.hooks['pre_change_branch_tip']
 
1532
        if not hooks:
 
1533
            return
 
1534
        old_revno, old_revid = self.last_revision_info()
 
1535
        params = ChangeBranchTipParams(
 
1536
            self, old_revno, new_revno, old_revid, new_revid)
 
1537
        for hook in hooks:
 
1538
            hook(params)
 
1539
 
1515
1540
    def _run_post_change_branch_tip_hooks(self, old_revno, old_revid):
1516
1541
        """Run the post_change_branch_tip hooks."""
1517
1542
        hooks = Branch.hooks['post_change_branch_tip']
1543
1568
        history = self._lefthand_history(revision_id)
1544
1569
        if len(history) != revno:
1545
1570
            raise AssertionError('%d != %d' % (len(history), revno))
 
1571
        self._run_pre_change_branch_tip_hooks(revno, revision_id)
1546
1572
        self.set_revision_history(history)
1547
1573
        self._run_post_change_branch_tip_hooks(old_revno, old_revid)
1548
1574
 
1958
1984
        old_revno, old_revid = self.last_revision_info()
1959
1985
        if self._get_append_revisions_only():
1960
1986
            self._check_history_violation(revision_id)
 
1987
        self._run_pre_change_branch_tip_hooks(revno, revision_id)
1961
1988
        self._write_last_revision_info(revno, revision_id)
1962
1989
        self._clear_cached_state()
1963
1990
        self._last_revision_info_cache = revno, revision_id