86
89
from bzrlib.revfile import Revfile
87
90
from bzrlib.weave import Weave
88
91
from bzrlib.weavefile import read_weave, write_weave
89
from bzrlib.progress import ProgressBar
92
from bzrlib.ui import ui_factory
90
93
from bzrlib.atomicfile import AtomicFile
91
94
from bzrlib.xml4 import serializer_v4
92
95
from bzrlib.xml5 import serializer_v5
112
115
self._backup_control_dir()
113
116
note('starting upgrade')
114
117
note('note: upgrade may be faster if all store files are ungzipped first')
115
self.pb = ProgressBar()
118
self.pb = ui_factory.progress_bar()
116
119
if not os.path.isdir(self.base + '/.bzr/weaves'):
117
120
os.mkdir(self.base + '/.bzr/weaves')
118
121
self.inv_weave = Weave('inventory')
266
269
"""Convert revision and all referenced objects to new format."""
267
270
rev = self.revisions[rev_id]
268
271
inv = self._load_old_inventory(rev_id)
269
for parent_id in rev.parent_ids[:]:
270
if parent_id in self.absent_revisions:
271
rev.parent_ids.remove(parent_id)
273
note('remove {%s} as parent of {%s}', parent_id, rev_id)
274
self._convert_revision_contents(rev, inv)
275
self._store_new_weave(rev, inv)
276
self._make_rev_ancestry(rev)
272
present_parents = [p for p in rev.parent_ids
273
if p not in self.absent_revisions]
274
self._convert_revision_contents(rev, inv, present_parents)
275
self._store_new_weave(rev, inv, present_parents)
276
self._make_rev_ancestry(rev, present_parents)
277
277
self.converted_revs.add(rev_id)
280
def _store_new_weave(self, rev, inv):
280
def _store_new_weave(self, rev, inv, present_parents):
281
281
# the XML is now updated with text versions
283
283
for file_id in inv:
287
287
assert hasattr(ie, 'revision'), \
288
288
'no revision on {%s} in {%s}' % \
289
289
(file_id, rev.revision_id)
291
290
new_inv_xml = serializer_v5.write_inventory_to_string(inv)
292
291
new_inv_sha1 = sha_string(new_inv_xml)
293
self.inv_weave.add(rev.revision_id, rev.parent_ids,
292
self.inv_weave.add(rev.revision_id,
294
294
new_inv_xml.splitlines(True),
296
296
rev.inventory_sha1 = new_inv_sha1
299
def _make_rev_ancestry(self, rev):
299
def _make_rev_ancestry(self, rev, present_parents):
300
300
rev_id = rev.revision_id
301
for parent_id in rev.parent_ids:
301
for parent_id in present_parents:
302
302
assert parent_id in self.converted_revs
304
lines = list(self.anc_weave.mash_iter(rev.parent_ids))
304
lines = list(self.anc_weave.mash_iter(present_parents))
307
307
lines.append(rev_id + '\n')
309
parent_ancestries = [self.ancestries[p] for p in rev.parent_ids]
309
parent_ancestries = [self.ancestries[p] for p in present_parents]
310
310
new_lines = merge_ancestry_lines(rev_id, parent_ancestries)
311
311
assert set(lines) == set(new_lines)
312
312
self.ancestries[rev_id] = new_lines
313
self.anc_weave.add(rev_id, rev.parent_ids, lines)
316
def _convert_revision_contents(self, rev, inv):
313
self.anc_weave.add(rev_id, present_parents, lines)
316
def _convert_revision_contents(self, rev, inv, present_parents):
317
317
"""Convert all the files within a revision.
319
319
Also upgrade the inventory to refer to the text revision ids."""
320
320
rev_id = rev.revision_id
321
321
mutter('converting texts of revision {%s}',
323
parent_invs = map(self._load_updated_inventory, rev.parent_ids)
323
parent_invs = map(self._load_updated_inventory, present_parents)
324
324
for file_id in inv:
325
325
ie = inv[file_id]
326
326
self._set_revision(rev, ie, parent_invs)