17
17
"""Full history branch formats."""
19
from __future__ import absolute_import
22
24
revision as _mod_revision,
25
from ..branch import (
27
from brzlib.branch import (
33
from ..trace import mutter_callsite
33
from brzlib.decorators import (
36
from brzlib.trace import mutter_callsite
36
39
class FullHistoryBzrBranch(BzrBranch):
37
40
"""Bzr branch which contains the full revision history."""
39
43
def set_last_revision_info(self, revno, revision_id):
40
if not revision_id or not isinstance(revision_id, bytes):
41
raise errors.InvalidRevisionId(
42
revision_id=revision_id, branch=self)
44
if not revision_id or not isinstance(revision_id, basestring):
45
raise errors.InvalidRevisionId(revision_id=revision_id, branch=self)
43
46
revision_id = _mod_revision.ensure_null(revision_id)
44
with self.lock_write():
45
# this old format stores the full history, but this api doesn't
46
# provide it, so we must generate, and might as well check it's
48
history = self._lefthand_history(revision_id)
49
if len(history) != revno:
50
raise AssertionError('%d != %d' % (len(history), revno))
51
self._set_revision_history(history)
47
# this old format stores the full history, but this api doesn't
48
# provide it, so we must generate, and might as well check it's
50
history = self._lefthand_history(revision_id)
51
if len(history) != revno:
52
raise AssertionError('%d != %d' % (len(history), revno))
53
self._set_revision_history(history)
53
55
def _read_last_revision_info(self):
54
56
rh = self._revision_history()
85
87
This performs the actual writing to disk.
86
88
It is intended to be called by set_revision_history."""
87
89
self._transport.put_bytes(
88
'revision-history', b'\n'.join(history),
89
mode=self.controldir._get_file_mode())
90
'revision-history', '\n'.join(history),
91
mode=self.bzrdir._get_file_mode())
91
93
def _gen_revision_history(self):
92
history = self._transport.get_bytes('revision-history').split(b'\n')
93
if history[-1:] == [b'']:
94
history = self._transport.get_bytes('revision-history').split('\n')
95
if history[-1:] == ['']:
94
96
# There shouldn't be a trailing newline, but just in case.
112
114
new_history = rev.get_history(self.repository)[1:]
113
115
destination._set_revision_history(new_history)
115
118
def generate_revision_history(self, revision_id, last_rev=None,
117
120
"""Create a new revision history that will finish with revision_id.
119
122
:param revision_id: the new tip to use.
122
125
:param other_branch: The other branch that DivergedBranches should
123
126
raise with respect to.
125
with self.lock_write():
126
self._set_revision_history(self._lefthand_history(revision_id,
127
last_rev, other_branch))
128
self._set_revision_history(self._lefthand_history(revision_id,
129
last_rev, other_branch))
130
132
class BzrBranch5(FullHistoryBzrBranch):
154
156
def get_format_string(cls):
155
157
"""See BranchFormat.get_format_string()."""
156
return b"Bazaar-NG branch format 5\n"
158
return "Bazaar-NG branch format 5\n"
158
160
def get_format_description(self):
159
161
"""See BranchFormat.get_format_description()."""
160
162
return "Branch format 5"
162
def initialize(self, a_controldir, name=None, repository=None,
164
def initialize(self, a_bzrdir, name=None, repository=None,
163
165
append_revisions_only=None):
164
"""Create a branch of this format in a_controldir."""
166
"""Create a branch of this format in a_bzrdir."""
165
167
if append_revisions_only:
166
raise errors.UpgradeRequired(a_controldir.user_url)
167
utf8_files = [('revision-history', b''),
168
('branch-name', b''),
168
raise errors.UpgradeRequired(a_bzrdir.user_url)
169
utf8_files = [('revision-history', ''),
170
return self._initialize_helper(a_controldir, utf8_files, name, repository)
172
return self._initialize_helper(a_bzrdir, utf8_files, name, repository)
172
174
def supports_tags(self):
175
supports_reference_locations = False