88
from bzrlib.branch import Branch, find_branch, BZR_BRANCH_FORMAT_5
88
from bzrlib.branch import Branch, find_branch
89
from bzrlib.branch import BZR_BRANCH_FORMAT_5, BZR_BRANCH_FORMAT_6
90
import bzrlib.hashcache as hashcache
89
91
from bzrlib.revfile import Revfile
90
92
from bzrlib.weave import Weave
91
93
from bzrlib.weavefile import read_weave, write_weave
113
115
note('starting upgrade of %s', os.path.abspath(self.base))
114
116
self._backup_control_dir()
115
note('starting upgrade')
117
self.pb = ui_factory.progress_bar()
118
if self.old_format == 4:
119
note('starting upgrade from format 4 to 5')
120
self._convert_to_weaves()
122
if self.old_format == 5:
123
note('starting upgrade from format 5 to 6')
124
self._convert_to_prefixed()
126
cache = hashcache.HashCache(os.path.abspath(self.base))
132
def _convert_to_prefixed(self):
133
from bzrlib.store import hash_prefix
134
for store_name in ["weaves", "revision-store"]:
135
note("adding prefixes to %s" % store_name)
136
store_dir = os.path.join(self.base, ".bzr", store_name)
137
for filename in os.listdir(store_dir):
138
if filename.endswith(".weave") or filename.endswith(".gz"):
139
file_id = os.path.splitext(filename)[0]
142
prefix_dir = os.path.join(store_dir, hash_prefix(file_id))
143
if not os.path.isdir(prefix_dir):
145
os.rename(os.path.join(store_dir, filename),
146
os.path.join(prefix_dir, filename))
147
self._set_new_format(BZR_BRANCH_FORMAT_6)
150
def _convert_to_weaves(self):
116
151
note('note: upgrade may be faster if all store files are ungzipped first')
117
self.pb = ui_factory.progress_bar()
118
152
if not os.path.isdir(self.base + '/.bzr/weaves'):
119
153
os.mkdir(self.base + '/.bzr/weaves')
120
154
self.inv_weave = Weave('inventory')
144
178
note(' %6d texts' % self.text_count)
145
179
self._write_all_weaves()
146
180
self._write_all_revs()
147
self._set_new_format()
148
181
self._cleanup_spare_files()
182
self._set_new_format(BZR_BRANCH_FORMAT_5)
151
185
def _open_branch(self):
152
186
self.branch = Branch.open_downlevel(self.base)
153
if self.branch._branch_format == 5:
154
note('this branch is already in the most current format')
187
self.old_format = self.branch._branch_format
188
if self.old_format == 6:
189
note('this branch is in the most current format')
156
if self.branch._branch_format != 4:
191
if self.old_format not in (4, 5):
157
192
raise BzrError("cannot upgrade from branch format %r" %
158
193
self.branch._branch_format)
162
def _set_new_format(self):
163
self.branch.put_controlfile('branch-format', BZR_BRANCH_FORMAT_5)
197
def _set_new_format(self, format):
198
self.branch.put_controlfile('branch-format', format)
166
201
def _cleanup_spare_files(self):
228
263
self.pb.update('loading revision',
229
264
len(self.revisions),
230
265
len(self.known_revisions))
231
if rev_id not in self.branch.revision_store:
266
if not self.branch.revision_store.has_id(rev_id):
233
268
note('revision {%s} not present in branch; '
234
269
'will be converted as a ghost',
236
271
self.absent_revisions.add(rev_id)
238
rev_xml = self.branch.revision_store[rev_id].read()
273
rev_xml = self.branch.revision_store.get(rev_id).read()
239
274
rev = serializer_v4.read_revision_from_string(rev_xml)
240
275
for parent_id in rev.parent_ids:
241
276
self.known_revisions.add(parent_id)
246
281
def _load_old_inventory(self, rev_id):
247
282
assert rev_id not in self.converted_revs
248
old_inv_xml = self.branch.inventory_store[rev_id].read()
283
old_inv_xml = self.branch.inventory_store.get(rev_id).read()
249
284
inv = serializer_v4.read_inventory_from_string(old_inv_xml)
250
285
rev = self.revisions[rev_id]
251
286
if rev.inventory_sha1:
341
376
parent_indexes = map(w.lookup, previous_revisions)
342
377
if ie.has_text():
343
file_lines = self.branch.text_store[ie.text_id].readlines()
378
file_lines = self.branch.text_store.get(ie.text_id).readlines()
344
379
assert sha_strings(file_lines) == ie.text_sha1
345
380
assert sum(map(len, file_lines)) == ie.text_size
346
381
w.add(rev_id, parent_indexes, file_lines, ie.text_sha1)