435
435
def snapshot(self, revision, path, previous_entries,
436
work_tree, commit_builder):
436
work_tree, commit_builder, store_if_unchanged):
437
437
"""Make a snapshot of this entry which may or may not have changed.
439
439
This means that all its fields are populated, that it has its
442
442
:return: True if anything was recorded
444
444
# cannot be unchanged unless there is only one parent file rev.
445
self._read_tree_state(path, work_tree)
445
# self._read_tree_state(path, work_tree)
446
446
if len(previous_entries) == 1:
447
447
parent_ie = previous_entries.values()[0]
448
448
if self._unchanged(parent_ie):
582
582
"""See InventoryEntry._put_on_disk."""
583
583
os.mkdir(fullpath)
585
def _snapshot_text(self, file_parents, work_tree, commit_builder):
586
"""See InventoryEntry._snapshot_text."""
587
commit_builder.modified_directory(self.file_id, file_parents)
591
586
class InventoryFile(InventoryEntry):
592
587
"""A file in an inventory."""
716
711
def _forget_tree_state(self):
717
712
self.text_sha1 = None
719
def snapshot(self, revision, path, previous_entries,
720
work_tree, commit_builder):
721
"""See InventoryEntry.snapshot."""
722
# Note: We use a custom implementation of this method for files
723
# because it's a performance critical part of commit.
725
# If this is the initial commit for this file, we know the sha is
726
# coming later so skip calculating it now (in _read_tree_state())
727
if len(previous_entries) == 0:
728
self.executable = work_tree.is_executable(self.file_id, path=path)
730
self._read_tree_state(path, work_tree)
732
# If nothing is changed from the sole parent, there's nothing to do
733
if len(previous_entries) == 1:
734
parent_ie = previous_entries.values()[0]
735
if self._unchanged(parent_ie):
736
self.revision = parent_ie.revision
739
# Add the file to the repository
740
self.revision = revision
741
def get_content_byte_lines():
742
return work_tree.get_file(self.file_id, path).readlines()
743
self.text_sha1, self.text_size = commit_builder.modified_file_text(
744
self.file_id, previous_entries, get_content_byte_lines,
745
self.text_sha1, self.text_size)
748
714
def _unchanged(self, previous_ie):
749
715
"""See InventoryEntry._unchanged."""
750
716
compatible = super(InventoryFile, self)._unchanged(previous_ie)
845
811
compatible = False
846
812
return compatible
848
def _snapshot_text(self, file_parents, work_tree, commit_builder):
849
"""See InventoryEntry._snapshot_text."""
850
commit_builder.modified_link(
851
self.file_id, file_parents, self.symlink_target)
855
815
class TreeReference(InventoryEntry):
866
826
return TreeReference(self.file_id, self.name, self.parent_id,
867
827
self.revision, self.reference_revision)
869
def _snapshot_text(self, file_parents, work_tree, commit_builder):
870
commit_builder.modified_reference(self.file_id, file_parents)
873
829
def _read_tree_state(self, path, work_tree):
874
830
"""Populate fields in the inventory entry from the given tree.