423
423
This means that all its fields are populated, that it has its
424
424
text stored in the text store or weave.
426
:return: True if anything was recorded
426
# mutter('new parents of %s are %r', path, previous_entries)
428
# cannot be unchanged unless there is only one parent file rev.
427
429
self._read_tree_state(path, work_tree)
428
# TODO: Where should we determine whether to reuse a
429
# previous revision id or create a new revision? 20060606
430
430
if len(previous_entries) == 1:
431
# cannot be unchanged unless there is only one parent file rev.
432
431
parent_ie = previous_entries.values()[0]
433
432
if self._unchanged(parent_ie):
434
# mutter("found unchanged entry")
435
433
self.revision = parent_ie.revision
437
return self._snapshot_into_revision(revision, previous_entries,
438
work_tree, commit_builder)
440
def _snapshot_into_revision(self, revision, previous_entries, work_tree,
442
"""Record this revision unconditionally into a store.
444
The entry's last-changed revision property (`revision`) is updated to
445
that of the new revision.
447
:param revision: id of the new revision that is being recorded.
449
:returns: String description of the commit (e.g. "merged", "modified"), etc.
451
# mutter('new revision {%s} for {%s}', revision, self.file_id)
452
435
self.revision = revision
453
self._snapshot_text(previous_entries, work_tree, commit_builder)
436
return self._snapshot_text(previous_entries, work_tree, commit_builder)
455
438
def _snapshot_text(self, file_parents, work_tree, commit_builder):
456
439
"""Record the 'text' of this entry, whatever form that takes.
458
This default implementation simply adds an empty text.
441
:return: True if anything was recorded
460
443
raise NotImplementedError(self._snapshot_text)
586
569
def _snapshot_text(self, file_parents, work_tree, commit_builder):
587
570
"""See InventoryEntry._snapshot_text."""
588
571
commit_builder.modified_directory(self.file_id, file_parents)
591
575
class InventoryFile(InventoryEntry):
716
700
def _forget_tree_state(self):
717
701
self.text_sha1 = None
719
def _snapshot_text(self, file_parents, work_tree, commit_builder):
720
"""See InventoryEntry._snapshot_text."""
703
def snapshot(self, revision, path, previous_entries,
704
work_tree, commit_builder):
705
"""See InventoryEntry.snapshot."""
706
# Note: We use a custom implementation of this method for files
707
# because it's a performance critical part of commit.
709
# If this is the initial commit for this file, we know the sha is
710
# coming later so skip calculating it now (in _read_tree_state())
711
if len(previous_entries) == 0:
712
self.executable = work_tree.is_executable(self.file_id, path=path)
714
self._read_tree_state(path, work_tree)
716
# If nothing is changed from the sole parent, there's nothing to do
717
if len(previous_entries) == 1:
718
parent_ie = previous_entries.values()[0]
719
if self._unchanged(parent_ie):
720
self.revision = parent_ie.revision
723
# Add the file to the repository
724
self.revision = revision
721
725
def get_content_byte_lines():
722
return work_tree.get_file(self.file_id).readlines()
726
return work_tree.get_file(self.file_id, path).readlines()
723
727
self.text_sha1, self.text_size = commit_builder.modified_file_text(
724
self.file_id, file_parents, get_content_byte_lines, self.text_sha1, self.text_size)
728
self.file_id, previous_entries, get_content_byte_lines,
729
self.text_sha1, self.text_size)
726
732
def _unchanged(self, previous_ie):
727
733
"""See InventoryEntry._unchanged."""
846
853
def _snapshot_text(self, file_parents, work_tree, commit_builder):
847
854
commit_builder.modified_reference(self.file_id, file_parents)
849
857
def _read_tree_state(self, path, work_tree):
850
858
"""Populate fields in the inventory entry from the given tree.