360
358
"""Given a revision id, return its revno"""
361
359
if revision_id is None:
363
revision_id = osutils.safe_revision_id(revision_id)
364
361
history = self.revision_history()
366
363
return history.index(revision_id) + 1
720
716
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()
762
719
class BzrBranchFormat4(BranchFormat):
763
720
"""Bzr branch format 4.
1129
1086
@needs_write_lock
1130
1087
def set_revision_history(self, rev_history):
1131
1088
"""See Branch.set_revision_history."""
1132
rev_history = [osutils.safe_revision_id(r) for r in rev_history]
1133
self.control_files.put_bytes(
1089
self.control_files.put_utf8(
1134
1090
'revision-history', '\n'.join(rev_history))
1135
1091
transaction = self.get_transaction()
1136
1092
history = transaction.map.find_revision_history()
1145
1101
# this call is disabled because revision_history is
1146
1102
# not really an object yet, and the transaction is for objects.
1147
1103
# transaction.register_clean(history)
1148
for hook in Branch.hooks['set_rh']:
1149
hook(self, rev_history)
1151
1105
@needs_read_lock
1152
1106
def revision_history(self):
1156
1110
if history is not None:
1157
1111
# mutter("cache hit for revision-history in %s", self)
1158
1112
return list(history)
1159
get_cached_utf8 = cache_utf8.get_cached_utf8
1160
history = [get_cached_utf8(l.rstrip('\r\n')) for l in
1113
decode_utf8 = cache_utf8.decode
1114
history = [decode_utf8(l.rstrip('\r\n')) for l in
1161
1115
self.control_files.get('revision-history').readlines()]
1162
1116
transaction.map.add_revision_history(history)
1163
1117
# this call is disabled because revision_history is
1176
1130
:param other_branch: The other branch that DivergedBranches should
1177
1131
raise with respect to.
1179
revision_id = osutils.safe_revision_id(revision_id)
1180
1133
# stop_revision must be a descendant of last_revision
1181
1134
stop_graph = self.repository.get_revision_graph(revision_id)
1182
1135
if last_rev is not None and last_rev not in stop_graph:
1205
1158
if stop_revision is None:
1206
1159
# if there are no commits, we're done.
1209
stop_revision = osutils.safe_revision_id(stop_revision)
1210
1161
# whats the current last revision, before we fetch [and change it
1212
1163
last_rev = self.last_revision()
1305
1256
"use bzrlib.urlutils.escape")
1307
1258
url = urlutils.relative_url(self.base, url)
1308
self.control_files.put_bytes('parent', url + '\n')
1259
self.control_files.put('parent', StringIO(url + '\n'))
1310
1261
@deprecated_function(zero_nine)
1311
1262
def tree_config(self):