412
412
def snapshot(self, revision, path, previous_entries,
413
work_tree, weave_store, transaction):
413
work_tree, weave_store, transaction, commit_builder):
414
414
"""Make a snapshot of this entry which may or may not have changed.
416
416
This means that all its fields are populated, that it has its
419
419
mutter('new parents of %s are %r', path, previous_entries)
420
420
self._read_tree_state(path, work_tree)
421
# TODO: Where should we determine whether to reuse a
422
# previous revision id or create a new revision? 20060606
421
423
if len(previous_entries) == 1:
422
424
# cannot be unchanged unless there is only one parent file rev.
423
425
parent_ie = previous_entries.values()[0]
426
428
self.revision = parent_ie.revision
427
429
return "unchanged"
428
430
return self._snapshot_into_revision(revision, previous_entries,
429
work_tree, weave_store, transaction)
431
work_tree, weave_store, transaction, commit_builder)
431
433
def _snapshot_into_revision(self, revision, previous_entries, work_tree,
432
weave_store, transaction):
434
weave_store, transaction, commit_builder):
433
435
"""Record this revision unconditionally into a store.
435
437
The entry's last-changed revision property (`revision`) is updated to
442
444
mutter('new revision {%s} for {%s}', revision, self.file_id)
443
445
self.revision = revision
444
446
self._snapshot_text(previous_entries, work_tree, weave_store,
447
transaction, commit_builder)
447
def _snapshot_text(self, file_parents, work_tree, weave_store, transaction):
449
def _snapshot_text(self, file_parents, work_tree, weave_store, transaction, commit_builder):
448
450
"""Record the 'text' of this entry, whatever form that takes.
450
452
This default implementation simply adds an empty text.
670
672
def _read_tree_state(self, path, work_tree):
671
673
"""See InventoryEntry._read_tree_state."""
672
674
self.text_sha1 = work_tree.get_file_sha1(self.file_id, path=path)
675
# FIXME: 20050930 probe for the text size when getting sha1
676
# in _read_tree_state
673
677
self.executable = work_tree.is_executable(self.file_id, path=path)
675
679
def _forget_tree_state(self):
676
680
self.text_sha1 = None
677
681
self.executable = None
679
def _snapshot_text(self, file_parents, work_tree, versionedfile_store, transaction):
683
def _snapshot_text(self, file_parents, work_tree, versionedfile_store, transaction, commit_builder):
680
684
"""See InventoryEntry._snapshot_text."""
681
mutter('storing text of file {%s} in revision {%s} into %r',
682
self.file_id, self.revision, versionedfile_store)
683
# special case to avoid diffing on renames or
685
if (len(file_parents) == 1
686
and self.text_sha1 == file_parents.values()[0].text_sha1
687
and self.text_size == file_parents.values()[0].text_size):
688
previous_ie = file_parents.values()[0]
689
versionedfile = versionedfile_store.get_weave(self.file_id, transaction)
690
versionedfile.clone_text(self.revision, previous_ie.revision, file_parents.keys())
692
new_lines = work_tree.get_file(self.file_id).readlines()
693
self._add_text_to_weave(new_lines, file_parents.keys(), versionedfile_store,
695
self.text_sha1 = sha_strings(new_lines)
696
self.text_size = sum(map(len, new_lines))
685
def get_content_byte_lines():
686
return work_tree.get_file(self.file_id).readlines()
687
self.text_sha1, self.text_size = commit_builder.record_file_text(
688
self.file_id, file_parents, get_content_byte_lines, self.text_sha1, self.text_size)
699
690
def _unchanged(self, previous_ie):
700
691
"""See InventoryEntry._unchanged."""