358
360
"""Given a revision id, return its revno"""
359
361
if revision_id is None:
363
revision_id = osutils.safe_revision_id(revision_id)
361
364
history = self.revision_history()
363
366
return history.index(revision_id) + 1
716
720
return self.get_format_string().rstrip()
723
class BranchHooks(dict):
724
"""A dictionary mapping hook name to a list of callables for branch hooks.
726
e.g. ['set_rh'] Is the list of items to be called when the
727
set_revision_history function is invoked.
731
"""Create the default hooks.
733
These are all empty initially, because by default nothing should get
737
# invoked whenever the revision history has been set
738
# with set_revision_history. The api signature is
739
# (branch, revision_history), and the branch will
740
# be write-locked. Introduced in 0.15.
743
def install_hook(self, hook_name, a_callable):
744
"""Install a_callable in to the hook hook_name.
746
:param hook_name: A hook name. See the __init__ method of BranchHooks
747
for the complete list of hooks.
748
:param a_callable: The callable to be invoked when the hook triggers.
749
The exact signature will depend on the hook - see the __init__
750
method of BranchHooks for details on each hook.
753
self[hook_name].append(a_callable)
755
raise errors.UnknownHook('branch', hook_name)
758
# install the default hooks into the Branch class.
759
Branch.hooks = BranchHooks()
719
762
class BzrBranchFormat4(BranchFormat):
720
763
"""Bzr branch format 4.
1086
1129
@needs_write_lock
1087
1130
def set_revision_history(self, rev_history):
1088
1131
"""See Branch.set_revision_history."""
1089
self.control_files.put_utf8(
1132
rev_history = [osutils.safe_revision_id(r) for r in rev_history]
1133
self.control_files.put_bytes(
1090
1134
'revision-history', '\n'.join(rev_history))
1091
1135
transaction = self.get_transaction()
1092
1136
history = transaction.map.find_revision_history()
1101
1145
# this call is disabled because revision_history is
1102
1146
# not really an object yet, and the transaction is for objects.
1103
1147
# transaction.register_clean(history)
1148
for hook in Branch.hooks['set_rh']:
1149
hook(self, rev_history)
1105
1151
@needs_read_lock
1106
1152
def revision_history(self):
1110
1156
if history is not None:
1111
1157
# mutter("cache hit for revision-history in %s", self)
1112
1158
return list(history)
1113
decode_utf8 = cache_utf8.decode
1114
history = [decode_utf8(l.rstrip('\r\n')) for l in
1159
get_cached_utf8 = cache_utf8.get_cached_utf8
1160
history = [get_cached_utf8(l.rstrip('\r\n')) for l in
1115
1161
self.control_files.get('revision-history').readlines()]
1116
1162
transaction.map.add_revision_history(history)
1117
1163
# this call is disabled because revision_history is
1130
1176
:param other_branch: The other branch that DivergedBranches should
1131
1177
raise with respect to.
1179
revision_id = osutils.safe_revision_id(revision_id)
1133
1180
# stop_revision must be a descendant of last_revision
1134
1181
stop_graph = self.repository.get_revision_graph(revision_id)
1135
1182
if last_rev is not None and last_rev not in stop_graph:
1158
1205
if stop_revision is None:
1159
1206
# if there are no commits, we're done.
1209
stop_revision = osutils.safe_revision_id(stop_revision)
1161
1210
# whats the current last revision, before we fetch [and change it
1163
1212
last_rev = self.last_revision()
1256
1305
"use bzrlib.urlutils.escape")
1258
1307
url = urlutils.relative_url(self.base, url)
1259
self.control_files.put('parent', StringIO(url + '\n'))
1308
self.control_files.put_bytes('parent', url + '\n')
1261
1310
@deprecated_function(zero_nine)
1262
1311
def tree_config(self):