92
92
from bzrlib.xml5 import serializer_v5
93
93
from bzrlib.trace import mutter, note, warning, enable_default_logging
94
94
from bzrlib.osutils import sha_strings, sha_string
95
from bzrlib.commit import merge_ancestry_lines
98
98
class Convert(object):
113
112
self.pb = ProgressBar()
114
113
self.inv_weave = Weave('__inventory')
115
114
self.anc_weave = Weave('__ancestry')
119
116
# holds in-memory weaves for all files
120
117
self.text_weaves = {}
122
b = self.branch = Branch('.', relax_version_check=True)
119
self.branch = Branch('.', relax_version_check=True)
125
rev_history = b.revision_history()
122
rev_history = self.branch.revision_history()
153
150
def _write_all_weaves(self):
151
write_a_weave(self.inv_weave, 'weaves/inventory.weave')
152
write_a_weave(self.anc_weave, 'weaves/ancestry.weave')
155
write_a_weave(self.inv_weave, 'weaves/inventory.weave')
157
155
for file_id, file_weave in self.text_weaves.items():
158
156
self.pb.update('writing weave', i, len(self.text_weaves))
208
205
"""Convert revision and all referenced objects to new format."""
209
206
rev = self.revisions[rev_id]
210
207
inv = self.inventories[rev_id]
208
for parent_id in rev.parent_ids[:]:
209
if parent_id in self.absent_revisions:
210
rev.parent_ids.remove(parent_id)
212
note('remove {%s} as parent of {%s}', parent_id, rev_id)
211
213
self._convert_revision_contents(rev, inv)
212
214
# the XML is now updated with text versions
213
215
new_inv_xml = serializer_v5.write_inventory_to_string(inv)
214
inv_parents = [x for x in self.revisions[rev_id].parent_ids
215
if x not in self.absent_revisions]
216
216
new_inv_sha1 = sha_string(new_inv_xml)
217
self.inv_weave.add(rev_id, inv_parents,
217
self.inv_weave.add(rev_id, rev.parent_ids,
218
218
new_inv_xml.splitlines(True),
220
220
# TODO: Upgrade revision XML and write that out
221
221
rev.inventory_sha1 = new_inv_sha1
222
self._make_rev_ancestry(rev)
222
223
self.converted_revs.add(rev_id)
226
def _make_rev_ancestry(self, rev):
227
rev_id = rev.revision_id
228
for parent_id in rev.parent_ids:
229
assert parent_id in self.converted_revs
230
parent_ancestries = [self.ancestries[p] for p in rev.parent_ids]
231
new_lines = merge_ancestry_lines(rev_id, parent_ancestries)
232
self.ancestries[rev_id] = new_lines
233
self.anc_weave.add(rev_id, rev.parent_ids, new_lines)
225
236
def _convert_revision_contents(self, rev, inv):
226
237
"""Convert all the files within a revision.
255
266
file_parents = []
256
267
text_changed = False
257
268
for parent_id in rev.parent_ids:
258
if parent_id in self.absent_revisions:
260
assert parent_id in self.converted_revs
269
##if parent_id in self.absent_revisions:
271
assert parent_id in self.converted_revs, \
272
'parent {%s} not converted' % parent_id
261
273
parent_inv = self.inventories[parent_id]
262
274
if parent_inv.has_id(file_id):
263
275
parent_ie = parent_inv[file_id]