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'] = []
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'] = []
1030
1036
# install the default hooks into the Branch class.
1031
1037
Branch.hooks = BranchHooks()
1040
class ChangeBranchTipParams(object):
1041
"""Object holding parameters passed to *_change_branch_tip hooks.
1043
There are 5 fields that hooks may wish to access:
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
1051
The revid fields are strings. The revno fields are integers.
1054
def __init__(self, branch, old_revno, new_revno, old_revid, new_revid):
1055
"""Create a group of ChangeBranchTip parameters.
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.
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
1034
1070
class BzrBranchFormat4(BranchFormat):
1035
1071
"""Bzr branch format 4.
1383
1419
for hook in Branch.hooks['set_rh']:
1384
1420
hook(self, rev_history)
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']
1427
new_revno, new_revid = self.last_revision_info()
1428
params = ChangeBranchTipParams(
1429
self, old_revno, new_revno, old_revid, new_revid)
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.
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)
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)
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)
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())