728
730
return self.get_format_string().rstrip()
733
class BranchHooks(dict):
734
"""A dictionary mapping hook name to a list of callables for branch hooks.
736
e.g. ['set_rh'] Is the list of items to be called when the
737
set_revision_history function is invoked.
741
"""Create the default hooks.
743
These are all empty initially, because by default nothing should get
747
# invoked whenever the revision history has been set
748
# with set_revision_history. The api signature is
749
# (branch, revision_history), and the branch will
750
# be write-locked. Introduced in 0.15.
753
def install_hook(self, hook_name, a_callable):
754
"""Install a_callable in to the hook hook_name.
756
:param hook_name: A hook name. See the __init__ method of BranchHooks
757
for the complete list of hooks.
758
:param a_callable: The callable to be invoked when the hook triggers.
759
The exact signature will depend on the hook - see the __init__
760
method of BranchHooks for details on each hook.
763
self[hook_name].append(a_callable)
765
raise errors.UnknownHook('branch', hook_name)
768
# install the default hooks into the Branch class.
769
Branch.hooks = BranchHooks()
731
772
class BzrBranchFormat4(BranchFormat):
732
773
"""Bzr branch format 4.
1098
1139
def append_revision(self, *revision_ids):
1099
1140
"""See Branch.append_revision."""
1100
1141
for revision_id in revision_ids:
1142
_mod_revision.check_not_reserved_id(revision_id)
1101
1143
mutter("add {%s} to revision-history" % revision_id)
1102
1144
rev_history = self.revision_history()
1103
1145
rev_history.extend(revision_ids)
1121
1163
# this call is disabled because revision_history is
1122
1164
# not really an object yet, and the transaction is for objects.
1123
1165
# transaction.register_clean(history)
1166
for hook in Branch.hooks['set_rh']:
1167
hook(self, rev_history)
1125
1169
@needs_read_lock
1126
1170
def revision_history(self):