~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-04-02 18:39:41 UTC
  • mfrom: (2376.2.9 inventory-delta)
  • Revision ID: pqm@pqm.ubuntu.com-20070402183941-55dc90797840300e
ImplementĀ WorkingTree.apply_inventory_delta

Show diffs side-by-side

added added

removed removed

Lines of Context:
738
738
        conflicts = self.find_conflicts()
739
739
        if len(conflicts) != 0:
740
740
            raise MalformedTransform(conflicts=conflicts)
741
 
        limbo_inv = {}
742
741
        inv = self._tree.inventory
 
742
        inventory_delta = []
743
743
        child_pb = bzrlib.ui.ui_factory.nested_progress_bar()
744
744
        try:
745
745
            child_pb.update('Apply phase', 0, 2)
746
 
            self._apply_removals(inv, limbo_inv)
 
746
            self._apply_removals(inv, inventory_delta)
747
747
            child_pb.update('Apply phase', 1, 2)
748
 
            modified_paths = self._apply_insertions(inv, limbo_inv)
 
748
            modified_paths = self._apply_insertions(inv, inventory_delta)
749
749
        finally:
750
750
            child_pb.finished()
751
 
        self._tree._write_inventory(inv)
 
751
        self._tree.apply_inventory_delta(inventory_delta)
752
752
        self.__done = True
753
753
        self.finalize()
754
754
        return _TransformResults(modified_paths)
757
757
        """Generate the limbo name of a file"""
758
758
        return pathjoin(self._limbodir, trans_id)
759
759
 
760
 
    def _apply_removals(self, inv, limbo_inv):
 
760
    def _apply_removals(self, inv, inventory_delta):
761
761
        """Perform tree operations that remove directory/inventory names.
762
762
        
763
763
        That is, delete files that are to be deleted, and put any files that
786
786
                        file_id = self._tree.inventory.root.file_id
787
787
                    else:
788
788
                        file_id = self.tree_file_id(trans_id)
789
 
                    del inv[file_id]
790
 
                elif trans_id in self._new_name or trans_id in self._new_parent:
791
 
                    file_id = self.tree_file_id(trans_id)
792
 
                    if file_id is not None:
793
 
                        limbo_inv[trans_id] = inv[file_id]
794
 
                        inv.remove_recursive_id(file_id)
 
789
                    assert file_id is not None
 
790
                    inventory_delta.append((path, None, file_id, None))
795
791
        finally:
796
792
            child_pb.finished()
797
793
 
798
 
    def _apply_insertions(self, inv, limbo_inv):
 
794
    def _apply_insertions(self, inv, inventory_delta):
799
795
        """Perform tree operations that insert directory/inventory names.
800
796
        
801
797
        That is, create any files that need to be created, and restore from
807
803
        child_pb = bzrlib.ui.ui_factory.nested_progress_bar()
808
804
        try:
809
805
            for num, (path, trans_id) in enumerate(new_paths):
 
806
                new_entry = None
810
807
                child_pb.update('adding file', num, len(new_paths))
811
808
                try:
812
809
                    kind = self._new_contents[trans_id]
829
826
                    if kind is None:
830
827
                        kind = file_kind(self._tree.abspath(path))
831
828
                    if trans_id in self._new_reference_revision:
832
 
                        entry = inventory.TreeReference(self._new_id[trans_id], 
 
829
                        new_entry = inventory.TreeReference(
 
830
                            self._new_id[trans_id],
833
831
                            self._new_name[trans_id], 
834
832
                            self.final_file_id(self._new_parent[trans_id]),
835
833
                            None, self._new_reference_revision[trans_id])
836
 
                        inv.add(entry)
837
834
                    else:
838
 
                        inv.add_path(path, kind, self._new_id[trans_id])
839
 
                elif trans_id in self._new_name or trans_id in\
840
 
                    self._new_parent:
841
 
                    entry = limbo_inv.get(trans_id)
842
 
                    if entry is not None:
843
 
                        entry.name = self.final_name(trans_id)
844
 
                        parent_path = os.path.dirname(path)
845
 
                        entry.parent_id = \
846
 
                            self._tree.inventory.path2id(parent_path)
847
 
                        inv.add(entry)
848
 
 
849
 
                # requires files and inventory entries to be in place
 
835
                        new_entry = inventory.make_entry(kind,
 
836
                            self.final_name(trans_id),
 
837
                            self.final_file_id(self.final_parent(trans_id)),
 
838
                            self._new_id[trans_id])
 
839
                else:
 
840
                    if trans_id in self._new_name or trans_id in\
 
841
                        self._new_parent or\
 
842
                        trans_id in self._new_executability:
 
843
                        file_id = self.final_file_id(trans_id)
 
844
                        if file_id is not None:
 
845
                            entry = inv[file_id]
 
846
                            new_entry = entry.copy()
 
847
 
 
848
                    if trans_id in self._new_name or trans_id in\
 
849
                        self._new_parent:
 
850
                            if new_entry is not None:
 
851
                                new_entry.name = self.final_name(trans_id)
 
852
                                parent = self.final_parent(trans_id)
 
853
                                parent_id = self.final_file_id(parent)
 
854
                                new_entry.parent_id = parent_id
 
855
 
850
856
                if trans_id in self._new_executability:
851
 
                    self._set_executability(path, inv, trans_id)
 
857
                    self._set_executability(path, new_entry, trans_id)
 
858
                if new_entry is not None:
 
859
                    if new_entry.file_id in inv:
 
860
                        old_path = inv.id2path(new_entry.file_id)
 
861
                    else:
 
862
                        old_path = None
 
863
                    inventory_delta.append((old_path, path,
 
864
                                            new_entry.file_id,
 
865
                                            new_entry))
852
866
        finally:
853
867
            child_pb.finished()
854
868
        return modified_paths
855
869
 
856
 
    def _set_executability(self, path, inv, trans_id):
 
870
    def _set_executability(self, path, entry, trans_id):
857
871
        """Set the executability of versioned files """
858
 
        file_id = inv.path2id(path)
859
872
        new_executability = self._new_executability[trans_id]
860
 
        inv[file_id].executable = new_executability
 
873
        entry.executable = new_executability
861
874
        if supports_executable():
862
875
            abspath = self._tree.abspath(path)
863
876
            current_mode = os.stat(abspath).st_mode