~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Aaron Bentley
  • Date: 2008-04-24 04:58:42 UTC
  • mfrom: (3377 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3380.
  • Revision ID: aaron@aaronbentley.com-20080424045842-0cajl9v6s4u52kaw
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1025
1025
        # local is the local branch or None, master is the target branch,
1026
1026
        # and an empty branch recieves new_revno of 0, new_revid of None.
1027
1027
        self['post_uncommit'] = []
 
1028
        # Introduced in 1.4
 
1029
        # Invoked after the tip of a branch changes.
 
1030
        # the api signature is
 
1031
        # (params) where params is a ChangeBranchTipParams with the members
 
1032
        # (branch, old_revno, new_revno, old_revid, new_revid)
 
1033
        self['post_change_branch_tip'] = []
1028
1034
 
1029
1035
 
1030
1036
# install the default hooks into the Branch class.
1031
1037
Branch.hooks = BranchHooks()
1032
1038
 
1033
1039
 
 
1040
class ChangeBranchTipParams(object):
 
1041
    """Object holding parameters passed to *_change_branch_tip hooks.
 
1042
 
 
1043
    There are 5 fields that hooks may wish to access:
 
1044
 
 
1045
    :ivar branch: the branch being changed
 
1046
    :ivar old_revno: revision number before the change
 
1047
    :ivar new_revno: revision number after the change
 
1048
    :ivar old_revid: revision id before the change
 
1049
    :ivar new_revid: revision id after the change
 
1050
 
 
1051
    The revid fields are strings. The revno fields are integers.
 
1052
    """
 
1053
 
 
1054
    def __init__(self, branch, old_revno, new_revno, old_revid, new_revid):
 
1055
        """Create a group of ChangeBranchTip parameters.
 
1056
 
 
1057
        :param branch: The branch being changed.
 
1058
        :param old_revno: Revision number before the change.
 
1059
        :param new_revno: Revision number after the change.
 
1060
        :param old_revid: Tip revision id before the change.
 
1061
        :param new_revid: Tip revision id after the change.
 
1062
        """
 
1063
        self.branch = branch
 
1064
        self.old_revno = old_revno
 
1065
        self.new_revno = new_revno
 
1066
        self.old_revid = old_revid
 
1067
        self.new_revid = new_revid
 
1068
 
 
1069
 
1034
1070
class BzrBranchFormat4(BranchFormat):
1035
1071
    """Bzr branch format 4.
1036
1072
 
1383
1419
        for hook in Branch.hooks['set_rh']:
1384
1420
            hook(self, rev_history)
1385
1421
 
 
1422
    def _run_post_change_branch_tip_hooks(self, old_revno, old_revid):
 
1423
        """Run the post_change_branch_tip hooks."""
 
1424
        hooks = Branch.hooks['post_change_branch_tip']
 
1425
        if not hooks:
 
1426
            return
 
1427
        new_revno, new_revid = self.last_revision_info()
 
1428
        params = ChangeBranchTipParams(
 
1429
            self, old_revno, new_revno, old_revid, new_revid)
 
1430
        for hook in hooks:
 
1431
            hook(params)
 
1432
 
1386
1433
    @needs_write_lock
1387
1434
    def set_last_revision_info(self, revno, revision_id):
1388
1435
        """Set the last revision of this branch.
1396
1443
        be permitted.
1397
1444
        """
1398
1445
        revision_id = _mod_revision.ensure_null(revision_id)
 
1446
        old_revno, old_revid = self.last_revision_info()
1399
1447
        history = self._lefthand_history(revision_id)
1400
1448
        assert len(history) == revno, '%d != %d' % (len(history), revno)
1401
1449
        self.set_revision_history(history)
 
1450
        self._run_post_change_branch_tip_hooks(old_revno, old_revid)
1402
1451
 
1403
1452
    def _gen_revision_history(self):
1404
1453
        history = self.control_files.get('revision-history').read().split('\n')
1854
1903
    @needs_write_lock
1855
1904
    def set_last_revision_info(self, revno, revision_id):
1856
1905
        revision_id = _mod_revision.ensure_null(revision_id)
 
1906
        old_revno, old_revid = self.last_revision_info()
1857
1907
        if self._get_append_revisions_only():
1858
1908
            self._check_history_violation(revision_id)
1859
1909
        self._write_last_revision_info(revno, revision_id)
1860
1910
        self._clear_cached_state()
1861
1911
        self._last_revision_info_cache = revno, revision_id
 
1912
        self._run_post_change_branch_tip_hooks(old_revno, old_revid)
1862
1913
 
1863
1914
    def _check_history_violation(self, revision_id):
1864
1915
        last_revision = _mod_revision.ensure_null(self.last_revision())
2149
2200
        new_branch = format.open(branch.bzrdir, _found=True)
2150
2201
 
2151
2202
        # Copy source data into target
2152
 
        new_branch.set_last_revision_info(*branch.last_revision_info())
 
2203
        new_branch._write_last_revision_info(*branch.last_revision_info())
2153
2204
        new_branch.set_parent(branch.get_parent())
2154
2205
        new_branch.set_bound_location(branch.get_bound_location())
2155
2206
        new_branch.set_push_location(branch.get_push_location())