~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: 2006-06-08 15:08:04 UTC
  • mfrom: (1740.3.10 commit_builder)
  • Revision ID: pqm@pqm.ubuntu.com-20060608150804-a186fa90bfede9a6
(jrv,rbc,jam) Refactor commit.Commit to use a Repository specific CommitBuilder, enables foreign branch commits

Show diffs side-by-side

added added

removed removed

Lines of Context:
127
127
                 'text_id', 'parent_id', 'children', 'executable', 
128
128
                 'revision']
129
129
 
130
 
    def _add_text_to_weave(self, new_lines, parents, weave_store, transaction):
131
 
        versionedfile = weave_store.get_weave_or_empty(self.file_id,
132
 
                                                       transaction)
133
 
        versionedfile.add_lines(self.revision, parents, new_lines)
134
 
        versionedfile.clear_cache()
135
 
 
136
130
    def detect_changes(self, old_entry):
137
131
        """Return a (text_modified, meta_modified) from this to old_entry.
138
132
        
410
404
                   self.parent_id))
411
405
 
412
406
    def snapshot(self, revision, path, previous_entries,
413
 
                 work_tree, weave_store, transaction):
 
407
                 work_tree, commit_builder):
414
408
        """Make a snapshot of this entry which may or may not have changed.
415
409
        
416
410
        This means that all its fields are populated, that it has its
418
412
        """
419
413
        mutter('new parents of %s are %r', path, previous_entries)
420
414
        self._read_tree_state(path, work_tree)
 
415
        # TODO: Where should we determine whether to reuse a
 
416
        # previous revision id or create a new revision? 20060606
421
417
        if len(previous_entries) == 1:
422
418
            # cannot be unchanged unless there is only one parent file rev.
423
419
            parent_ie = previous_entries.values()[0]
426
422
                self.revision = parent_ie.revision
427
423
                return "unchanged"
428
424
        return self._snapshot_into_revision(revision, previous_entries, 
429
 
                                            work_tree, weave_store, transaction)
 
425
                                            work_tree, commit_builder)
430
426
 
431
427
    def _snapshot_into_revision(self, revision, previous_entries, work_tree,
432
 
                                weave_store, transaction):
 
428
                                commit_builder):
433
429
        """Record this revision unconditionally into a store.
434
430
 
435
431
        The entry's last-changed revision property (`revision`) is updated to 
441
437
        """
442
438
        mutter('new revision {%s} for {%s}', revision, self.file_id)
443
439
        self.revision = revision
444
 
        self._snapshot_text(previous_entries, work_tree, weave_store,
445
 
                            transaction)
 
440
        self._snapshot_text(previous_entries, work_tree, commit_builder)
446
441
 
447
 
    def _snapshot_text(self, file_parents, work_tree, weave_store, transaction): 
 
442
    def _snapshot_text(self, file_parents, work_tree, commit_builder): 
448
443
        """Record the 'text' of this entry, whatever form that takes.
449
444
        
450
445
        This default implementation simply adds an empty text.
451
446
        """
452
 
        mutter('storing file {%s} in revision {%s}',
453
 
               self.file_id, self.revision)
454
 
        self._add_text_to_weave([], file_parents.keys(), weave_store, transaction)
 
447
        raise NotImplementedError(self._snapshot_text)
455
448
 
456
449
    def __eq__(self, other):
457
450
        if not isinstance(other, InventoryEntry):
562
555
        """See InventoryEntry._put_on_disk."""
563
556
        os.mkdir(fullpath)
564
557
 
 
558
    def _snapshot_text(self, file_parents, work_tree, commit_builder):
 
559
        """See InventoryEntry._snapshot_text."""
 
560
        commit_builder.modified_directory(self.file_id, file_parents)
 
561
 
565
562
 
566
563
class InventoryFile(InventoryEntry):
567
564
    """A file in an inventory."""
670
667
    def _read_tree_state(self, path, work_tree):
671
668
        """See InventoryEntry._read_tree_state."""
672
669
        self.text_sha1 = work_tree.get_file_sha1(self.file_id, path=path)
 
670
        # FIXME: 20050930 probe for the text size when getting sha1
 
671
        # in _read_tree_state
673
672
        self.executable = work_tree.is_executable(self.file_id, path=path)
674
673
 
675
674
    def _forget_tree_state(self):
676
675
        self.text_sha1 = None
677
676
        self.executable = None
678
677
 
679
 
    def _snapshot_text(self, file_parents, work_tree, versionedfile_store, transaction):
 
678
    def _snapshot_text(self, file_parents, work_tree, commit_builder):
680
679
        """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 
684
 
        # reparenting
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())
691
 
        else:
692
 
            new_lines = work_tree.get_file(self.file_id).readlines()
693
 
            self._add_text_to_weave(new_lines, file_parents.keys(), versionedfile_store,
694
 
                                    transaction)
695
 
            self.text_sha1 = sha_strings(new_lines)
696
 
            self.text_size = sum(map(len, new_lines))
697
 
 
 
680
        def get_content_byte_lines():
 
681
            return work_tree.get_file(self.file_id).readlines()
 
682
        self.text_sha1, self.text_size = commit_builder.modified_file_text(
 
683
            self.file_id, file_parents, get_content_byte_lines, self.text_sha1, self.text_size)
698
684
 
699
685
    def _unchanged(self, previous_ie):
700
686
        """See InventoryEntry._unchanged."""
794
780
            compatible = False
795
781
        return compatible
796
782
 
 
783
    def _snapshot_text(self, file_parents, work_tree, commit_builder):
 
784
        """See InventoryEntry._snapshot_text."""
 
785
        commit_builder.modified_link(
 
786
            self.file_id, file_parents, self.symlink_target)
 
787
 
797
788
 
798
789
class Inventory(object):
799
790
    """Inventory of versioned files in a tree.