323
323
parent_invs = map(self._load_updated_inventory, present_parents)
324
324
for file_id in inv:
325
325
ie = inv[file_id]
326
self._set_revision(rev, ie, parent_invs)
327
if not ie.has_text():
329
326
self._convert_file_version(rev, ie, parent_invs)
332
def _set_revision(self, rev, ie, parent_invs):
333
"""Set name version for a file.
336
if ie.kind == 'root_directory':
338
if len(parent_invs) == 0:
339
ie.revision = rev.revision_id
342
for p_inv in parent_invs:
343
if not p_inv.has_id(file_id):
344
ie.revision = rev.revision_id
346
old_ie = p_inv[file_id]
347
if (old_ie.parent_id != ie.parent_id
348
or old_ie.name != ie.name
349
or old_ie.text_sha1 != ie.text_sha1
350
or old_ie.text_size != ie.text_size):
351
ie.revision = rev.revision_id
353
if matched_id is None:
354
matched_id = old_ie.revision
355
elif matched_id != old_ie.revision:
356
ie.revision = rev.revision_id
359
assert matched_id is not None
360
ie.revision = matched_id
362
328
def _convert_file_version(self, rev, ie, parent_invs):
363
329
"""Convert one version of one file.
365
331
The file needs to be added into the weave if it is a merge
366
332
of >=2 parents or if it's changed from its parent.
334
if ie.kind == 'root_directory':
368
336
file_id = ie.file_id
369
337
rev_id = rev.revision_id
370
338
w = self.text_weaves.get(file_id)
372
340
w = Weave(file_id)
373
341
self.text_weaves[file_id] = w
375
342
text_changed = False
376
for parent_inv in parent_invs:
377
if parent_inv.has_id(file_id):
378
parent_ie = parent_inv[file_id]
379
old_revision = parent_ie.revision
343
previous_entries = ie.find_previous_heads(parent_invs, w)
344
for old_revision in previous_entries:
380
345
# if this fails, its a ghost ?
381
346
assert old_revision in self.converted_revs
382
if old_revision not in file_parents:
383
file_parents.append(old_revision)
384
if parent_ie.text_sha1 != ie.text_sha1:
386
if len(file_parents) != 1 or text_changed:
347
self.snapshot_ie(previous_entries, ie, w, rev_id)
349
assert getattr(ie, 'revision', None) is not None
351
def snapshot_ie(self, previous_revisions, ie, w, rev_id):
352
# TODO: convert this logic, which is ~= snapshot to
353
# a call to:. This needs the path figured out. rather than a work_tree
354
# a v4 revision_tree can be given, or something that looks enough like
355
# one to give the file content to the entry if it needs it.
356
# and we need something that looks like a weave store for snapshot to
358
#ie.snapshot(rev, PATH, previous_revisions, REVISION_TREE, InMemoryWeaveStore(self.text_weaves))
359
if len(previous_revisions) == 1:
360
previous_ie = previous_revisions.values()[0]
361
if ie._unchanged(previous_ie):
362
ie.revision = previous_ie.revision
364
parent_indexes = map(w.lookup, previous_revisions)
387
366
file_lines = self.branch.text_store[ie.text_id].readlines()
388
367
assert sha_strings(file_lines) == ie.text_sha1
389
368
assert sum(map(len, file_lines)) == ie.text_size
390
w.add(rev_id, file_parents, file_lines, ie.text_sha1)
369
w.add(rev_id, parent_indexes, file_lines, ie.text_sha1)
392
370
self.text_count += 1
393
##mutter('import text {%s} of {%s}',
394
## ie.text_id, file_id)
396
##mutter('text of {%s} unchanged from parent', file_id)
397
ie.revision = file_parents[0]
372
w.add(rev_id, parent_indexes, [], None)
374
##mutter('import text {%s} of {%s}',
375
## ie.text_id, file_id)
402
377
def _make_order(self):
403
378
"""Return a suitable order for importing revisions.