~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/inventory.py

  • Committer: Ian Clatworthy
  • Date: 2007-08-31 05:54:21 UTC
  • mfrom: (2743.3.6 bzr.quicker-initial-commit)
  • mto: This revision was merged to the branch mainline in revision 2774.
  • Revision ID: ian.clatworthy@internode.on.net-20070831055421-iwcem9phv1needkk
(Ian Clatworthy) Quicker initial commit - skip SHAing twice & skip path lookup as we know it

Show diffs side-by-side

added added

removed removed

Lines of Context:
422
422
        
423
423
        This means that all its fields are populated, that it has its
424
424
        text stored in the text store or weave.
 
425
 
 
426
        :return: True if anything was recorded
425
427
        """
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
436
 
                return "unchanged"
437
 
        return self._snapshot_into_revision(revision, previous_entries, 
438
 
                                            work_tree, commit_builder)
439
 
 
440
 
    def _snapshot_into_revision(self, revision, previous_entries, work_tree,
441
 
                                commit_builder):
442
 
        """Record this revision unconditionally into a store.
443
 
 
444
 
        The entry's last-changed revision property (`revision`) is updated to 
445
 
        that of the new revision.
446
 
        
447
 
        :param revision: id of the new revision that is being recorded.
448
 
 
449
 
        :returns: String description of the commit (e.g. "merged", "modified"), etc.
450
 
        """
451
 
        # mutter('new revision {%s} for {%s}', revision, self.file_id)
 
434
                return False
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)
454
437
 
455
438
    def _snapshot_text(self, file_parents, work_tree, commit_builder): 
456
439
        """Record the 'text' of this entry, whatever form that takes.
457
 
        
458
 
        This default implementation simply adds an empty text.
 
440
 
 
441
        :return: True if anything was recorded
459
442
        """
460
443
        raise NotImplementedError(self._snapshot_text)
461
444
 
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)
 
572
        return True
589
573
 
590
574
 
591
575
class InventoryFile(InventoryEntry):
716
700
    def _forget_tree_state(self):
717
701
        self.text_sha1 = None
718
702
 
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.
 
708
 
 
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)
 
713
        else:
 
714
            self._read_tree_state(path, work_tree)
 
715
 
 
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
 
721
                return False
 
722
 
 
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)
 
730
        return True
725
731
 
726
732
    def _unchanged(self, previous_ie):
727
733
        """See InventoryEntry._unchanged."""
827
833
        """See InventoryEntry._snapshot_text."""
828
834
        commit_builder.modified_link(
829
835
            self.file_id, file_parents, self.symlink_target)
 
836
        return True
830
837
 
831
838
 
832
839
class TreeReference(InventoryEntry):
845
852
 
846
853
    def _snapshot_text(self, file_parents, work_tree, commit_builder):
847
854
        commit_builder.modified_reference(self.file_id, file_parents)
 
855
        return True
848
856
 
849
857
    def _read_tree_state(self, path, work_tree):
850
858
        """Populate fields in the inventory entry from the given tree.