364
364
r[ie.revision] = ie
367
def _snapshot_entry(self, path, ie, previous_entries):
368
"""Store a single possibly changed inventory entry in the branch."""
369
mutter('parents of %s are %r', path, previous_entries)
370
if ie.revision is not None:
371
# not selected for commit
373
if ie.kind == 'symlink':
374
ie.read_symlink_target(self.branch.abspath(path))
375
if len(previous_entries) == 1:
376
# cannot be unchanged unless there is only one parent file rev.
377
parent_ie = previous_entries.values()[0]
378
unchanged = ie.unchanged(parent_ie, self.work_tree)
380
mutter("found unchanged entry")
381
ie.revision = parent_ie.revision
382
self.report_entry_status(previous_entries, path, ie)
384
mutter('new revision for {%s}', ie.file_id)
385
ie.revision = self.rev_id
386
if ie.kind != 'file':
387
self.report_entry_status(previous_entries, path, ie)
389
# file is either new, or a file merge; need to record
391
self.report_entry_status(previous_entries, path, ie)
393
self._commit_file(ie, previous_entries)
395
def report_entry_status(self, previous_entries, path, ie):
396
if len(previous_entries) > 1:
397
note('merged %s', path)
398
elif len(previous_entries) == 0:
399
note('added %s', path)
400
elif ie.revision == self.rev_id:
401
note('modified/renamed/reparented%s', path)
403
note('unchanged %s', path)
405
367
def _store_snapshot(self):
406
368
"""Pass over inventory and record a snapshot.
425
387
for path, ie in self.new_inv.iter_entries():
426
388
previous_entries = self._find_entry_parents(ie. file_id)
427
self._snapshot_entry(path, ie, previous_entries)
389
if ie.revision is None:
390
change = ie.snapshot(self.rev_id, path, previous_entries,
391
self.work_tree, self.weave_store)
394
note("%s %s", change, path)
429
396
def _populate_new_inv(self):
430
397
"""Build revision inventory.
461
428
if file_id not in self.new_inv:
462
429
note('deleted %s', self.basis_inv.id2path(file_id))
464
def _commit_file(self, new_ie, file_parents):
465
mutter('storing file {%s} in revision {%s}',
466
new_ie.file_id, new_ie.revision)
467
# special case to avoid diffing on renames or
469
if (len(file_parents) == 1
470
and new_ie.text_sha1 == file_parents.values()[0].text_sha1
471
and new_ie.text_size == file_parents.values()[0].text_size):
472
previous_ie = file_parents.values()[0]
473
self.weave_store.add_identical_text(
474
new_ie.file_id, previous_ie.revision,
475
new_ie.revision, file_parents)
477
new_lines = self.work_tree.get_file(new_ie.file_id).readlines()
478
self._add_text_to_weave(new_ie.file_id, new_lines, file_parents)
479
new_ie.text_sha1 = sha_strings(new_lines)
480
new_ie.text_size = sum(map(len, new_lines))
482
def _add_text_to_weave(self, file_id, new_lines, parents):
483
self.weave_store.add_text(file_id, self.rev_id, new_lines, parents)
485
433
def _gen_revision_id(branch, when):
486
434
"""Return new revision-id."""