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