~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/inventory.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-10-03 05:04:42 UTC
  • mfrom: (2776.4.19 commit)
  • Revision ID: pqm@pqm.ubuntu.com-20071003050442-e0x9ofdfo0hwxnal
(robertc) Move serialisation of inventory entries into CommitBuilder. (Robert Collins)

Show diffs side-by-side

added added

removed removed

Lines of Context:
432
432
                   self.parent_id,
433
433
                   self.revision))
434
434
 
435
 
    def snapshot(self, revision, path, previous_entries,
436
 
                 work_tree, commit_builder):
437
 
        """Make a snapshot of this entry which may or may not have changed.
438
 
        
439
 
        This means that all its fields are populated, that it has its
440
 
        text stored in the text store or weave.
441
 
 
442
 
        :return: True if anything was recorded
443
 
        """
444
 
        # cannot be unchanged unless there is only one parent file rev.
445
 
        self._read_tree_state(path, work_tree)
446
 
        if len(previous_entries) == 1:
447
 
            parent_ie = previous_entries.values()[0]
448
 
            if self._unchanged(parent_ie):
449
 
                self.revision = parent_ie.revision
450
 
                return False
451
 
        self.revision = revision
452
 
        return self._snapshot_text(previous_entries, work_tree, commit_builder)
453
 
 
454
 
    def _snapshot_text(self, file_parents, work_tree, commit_builder): 
455
 
        """Record the 'text' of this entry, whatever form that takes.
456
 
 
457
 
        :return: True if anything was recorded
458
 
        """
459
 
        raise NotImplementedError(self._snapshot_text)
460
 
 
461
435
    def __eq__(self, other):
462
436
        if not isinstance(other, InventoryEntry):
463
437
            return NotImplemented
582
556
        """See InventoryEntry._put_on_disk."""
583
557
        os.mkdir(fullpath)
584
558
 
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)
588
 
        return True
589
 
 
590
559
 
591
560
class InventoryFile(InventoryEntry):
592
561
    """A file in an inventory."""
716
685
    def _forget_tree_state(self):
717
686
        self.text_sha1 = None
718
687
 
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.
724
 
 
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)
729
 
        else:
730
 
            self._read_tree_state(path, work_tree)
731
 
 
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
737
 
                return False
738
 
 
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)
746
 
        return True
747
 
 
748
688
    def _unchanged(self, previous_ie):
749
689
        """See InventoryEntry._unchanged."""
750
690
        compatible = super(InventoryFile, self)._unchanged(previous_ie)
845
785
            compatible = False
846
786
        return compatible
847
787
 
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)
852
 
        return True
853
 
 
854
788
 
855
789
class TreeReference(InventoryEntry):
856
790
    
866
800
        return TreeReference(self.file_id, self.name, self.parent_id,
867
801
                             self.revision, self.reference_revision)
868
802
 
869
 
    def _snapshot_text(self, file_parents, work_tree, commit_builder):
870
 
        commit_builder.modified_reference(self.file_id, file_parents)
871
 
        return True
872
 
 
873
803
    def _read_tree_state(self, path, work_tree):
874
804
        """Populate fields in the inventory entry from the given tree.
875
805
        """