~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transform.py

Merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
                           ExistingLimbo, ImmortalLimbo)
24
24
from bzrlib.inventory import InventoryEntry
25
25
from bzrlib.osutils import file_kind, supports_executable, pathjoin
26
 
from bzrlib.progress import DummyProgress
 
26
from bzrlib.progress import DummyProgress, ProgressPhase
27
27
from bzrlib.trace import mutter, warning
 
28
import bzrlib.ui 
28
29
 
29
30
 
30
31
ROOT_PARENT = "root-parent"
665
666
            raise MalformedTransform(conflicts=conflicts)
666
667
        limbo_inv = {}
667
668
        inv = self._tree.inventory
668
 
        self._apply_removals(inv, limbo_inv)
669
 
        modified_paths = self._apply_insertions(inv, limbo_inv)
 
669
        child_pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
670
        try:
 
671
            child_pb.update('Apply phase', 0, 2)
 
672
            self._apply_removals(inv, limbo_inv)
 
673
            child_pb.update('Apply phase', 1, 2)
 
674
            modified_paths = self._apply_insertions(inv, limbo_inv)
 
675
        finally:
 
676
            child_pb.finished()
670
677
        self._tree._write_inventory(inv)
671
678
        self.__done = True
672
679
        self.finalize()
685
692
        """
686
693
        tree_paths = list(self._tree_path_ids.iteritems())
687
694
        tree_paths.sort(reverse=True)
688
 
        for num, data in enumerate(tree_paths):
689
 
            path, trans_id = data
690
 
            self._pb.update('removing file', num+1, len(tree_paths))
691
 
            full_path = self._tree.abspath(path)
692
 
            if trans_id in self._removed_contents:
693
 
                self.delete_any(full_path)
694
 
            elif trans_id in self._new_name or trans_id in self._new_parent:
695
 
                try:
696
 
                    os.rename(full_path, self._limbo_name(trans_id))
697
 
                except OSError, e:
698
 
                    if e.errno != errno.ENOENT:
699
 
                        raise
700
 
            if trans_id in self._removed_id:
701
 
                if trans_id == self._new_root:
702
 
                    file_id = self._tree.inventory.root.file_id
703
 
                else:
 
695
        child_pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
696
        try:
 
697
            for num, data in enumerate(tree_paths):
 
698
                path, trans_id = data
 
699
                child_pb.update('removing file', num, len(tree_paths))
 
700
                full_path = self._tree.abspath(path)
 
701
                if trans_id in self._removed_contents:
 
702
                    self.delete_any(full_path)
 
703
                elif trans_id in self._new_name or trans_id in \
 
704
                    self._new_parent:
 
705
                    try:
 
706
                        os.rename(full_path, self._limbo_name(trans_id))
 
707
                    except OSError, e:
 
708
                        if e.errno != errno.ENOENT:
 
709
                            raise
 
710
                if trans_id in self._removed_id:
 
711
                    if trans_id == self._new_root:
 
712
                        file_id = self._tree.inventory.root.file_id
 
713
                    else:
 
714
                        file_id = self.tree_file_id(trans_id)
 
715
                    del inv[file_id]
 
716
                elif trans_id in self._new_name or trans_id in self._new_parent:
704
717
                    file_id = self.tree_file_id(trans_id)
705
 
                del inv[file_id]
706
 
            elif trans_id in self._new_name or trans_id in self._new_parent:
707
 
                file_id = self.tree_file_id(trans_id)
708
 
                if file_id is not None:
709
 
                    limbo_inv[trans_id] = inv[file_id]
710
 
                    del inv[file_id]
711
 
        self._pb.clear()
 
718
                    if file_id is not None:
 
719
                        limbo_inv[trans_id] = inv[file_id]
 
720
                        del inv[file_id]
 
721
        finally:
 
722
            child_pb.finished()
712
723
 
713
724
    def _apply_insertions(self, inv, limbo_inv):
714
725
        """Perform tree operations that insert directory/inventory names.
719
730
        """
720
731
        new_paths = self.new_paths()
721
732
        modified_paths = []
722
 
        for num, (path, trans_id) in enumerate(new_paths):
723
 
            self._pb.update('adding file', num+1, len(new_paths))
724
 
            try:
725
 
                kind = self._new_contents[trans_id]
726
 
            except KeyError:
727
 
                kind = contents = None
728
 
            if trans_id in self._new_contents or self.path_changed(trans_id):
729
 
                full_path = self._tree.abspath(path)
 
733
        child_pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
734
        try:
 
735
            for num, (path, trans_id) in enumerate(new_paths):
 
736
                child_pb.update('adding file', num, len(new_paths))
730
737
                try:
731
 
                    os.rename(self._limbo_name(trans_id), full_path)
732
 
                except OSError, e:
733
 
                    # We may be renaming a dangling inventory id
734
 
                    if e.errno != errno.ENOENT:
735
 
                        raise
736
 
                if trans_id in self._new_contents:
737
 
                    modified_paths.append(full_path)
738
 
                    del self._new_contents[trans_id]
739
 
 
740
 
            if trans_id in self._new_id:
741
 
                if kind is None:
742
 
                    kind = file_kind(self._tree.abspath(path))
743
 
                inv.add_path(path, kind, self._new_id[trans_id])
744
 
            elif trans_id in self._new_name or trans_id in self._new_parent:
745
 
                entry = limbo_inv.get(trans_id)
746
 
                if entry is not None:
747
 
                    entry.name = self.final_name(trans_id)
748
 
                    parent_path = os.path.dirname(path)
749
 
                    entry.parent_id = self._tree.inventory.path2id(parent_path)
750
 
                    inv.add(entry)
751
 
 
752
 
            # requires files and inventory entries to be in place
753
 
            if trans_id in self._new_executability:
754
 
                self._set_executability(path, inv, trans_id)
755
 
        self._pb.clear()
 
738
                    kind = self._new_contents[trans_id]
 
739
                except KeyError:
 
740
                    kind = contents = None
 
741
                if trans_id in self._new_contents or \
 
742
                    self.path_changed(trans_id):
 
743
                    full_path = self._tree.abspath(path)
 
744
                    try:
 
745
                        os.rename(self._limbo_name(trans_id), full_path)
 
746
                    except OSError, e:
 
747
                        # We may be renaming a dangling inventory id
 
748
                        if e.errno != errno.ENOENT:
 
749
                            raise
 
750
                    if trans_id in self._new_contents:
 
751
                        modified_paths.append(full_path)
 
752
                        del self._new_contents[trans_id]
 
753
 
 
754
                if trans_id in self._new_id:
 
755
                    if kind is None:
 
756
                        kind = file_kind(self._tree.abspath(path))
 
757
                    inv.add_path(path, kind, self._new_id[trans_id])
 
758
                elif trans_id in self._new_name or trans_id in\
 
759
                    self._new_parent:
 
760
                    entry = limbo_inv.get(trans_id)
 
761
                    if entry is not None:
 
762
                        entry.name = self.final_name(trans_id)
 
763
                        parent_path = os.path.dirname(path)
 
764
                        entry.parent_id = \
 
765
                            self._tree.inventory.path2id(parent_path)
 
766
                        inv.add(entry)
 
767
 
 
768
                # requires files and inventory entries to be in place
 
769
                if trans_id in self._new_executability:
 
770
                    self._set_executability(path, inv, trans_id)
 
771
        finally:
 
772
            child_pb.finished()
756
773
        return modified_paths
757
774
 
758
775
    def _set_executability(self, path, inv, trans_id):
1020
1037
            except KeyError:
1021
1038
                return tt.trans_id_tree_file_id(file_id)
1022
1039
 
 
1040
        pp = ProgressPhase("Revert phase", 4, pb)
 
1041
        pp.next_phase()
1023
1042
        sorted_interesting = [i for i in topology_sorted_ids(target_tree) if
1024
1043
                              interesting(i)]
1025
 
        for id_num, file_id in enumerate(sorted_interesting):
1026
 
            pb.update("Reverting file", id_num+1, len(sorted_interesting))
1027
 
            if file_id not in working_tree.inventory:
1028
 
                entry = target_tree.inventory[file_id]
1029
 
                parent_id = trans_id_file_id(entry.parent_id)
1030
 
                e_trans_id = new_by_entry(tt, entry, parent_id, target_tree)
1031
 
                trans_id[file_id] = e_trans_id
1032
 
            else:
1033
 
                backup_this = backups
1034
 
                if file_id in merge_modified:
1035
 
                    backup_this = False
1036
 
                    del merge_modified[file_id]
1037
 
                change_entry(tt, file_id, working_tree, target_tree, 
1038
 
                             trans_id_file_id, backup_this, trans_id)
 
1044
        child_pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
1045
        try:
 
1046
            for id_num, file_id in enumerate(sorted_interesting):
 
1047
                child_pb.update("Reverting file", id_num+1, 
 
1048
                                len(sorted_interesting))
 
1049
                if file_id not in working_tree.inventory:
 
1050
                    entry = target_tree.inventory[file_id]
 
1051
                    parent_id = trans_id_file_id(entry.parent_id)
 
1052
                    e_trans_id = new_by_entry(tt, entry, parent_id, target_tree)
 
1053
                    trans_id[file_id] = e_trans_id
 
1054
                else:
 
1055
                    backup_this = backups
 
1056
                    if file_id in merge_modified:
 
1057
                        backup_this = False
 
1058
                        del merge_modified[file_id]
 
1059
                    change_entry(tt, file_id, working_tree, target_tree, 
 
1060
                                 trans_id_file_id, backup_this, trans_id)
 
1061
        finally:
 
1062
            child_pb.finished()
 
1063
        pp.next_phase()
1039
1064
        wt_interesting = [i for i in working_tree.inventory if interesting(i)]
1040
 
        for id_num, file_id in enumerate(wt_interesting):
1041
 
            pb.update("New file check", id_num+1, len(sorted_interesting))
1042
 
            if file_id not in target_tree:
1043
 
                trans_id = tt.trans_id_tree_file_id(file_id)
1044
 
                tt.unversion_file(trans_id)
1045
 
                if file_id in merge_modified:
1046
 
                    tt.delete_contents(trans_id)
1047
 
                    del merge_modified[file_id]
1048
 
        raw_conflicts = resolve_conflicts(tt, pb)
 
1065
        child_pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
1066
        try:
 
1067
            for id_num, file_id in enumerate(wt_interesting):
 
1068
                child_pb.update("New file check", id_num+1, 
 
1069
                                len(sorted_interesting))
 
1070
                if file_id not in target_tree:
 
1071
                    trans_id = tt.trans_id_tree_file_id(file_id)
 
1072
                    tt.unversion_file(trans_id)
 
1073
                    if file_id in merge_modified:
 
1074
                        tt.delete_contents(trans_id)
 
1075
                        del merge_modified[file_id]
 
1076
        finally:
 
1077
            child_pb.finished()
 
1078
        pp.next_phase()
 
1079
        child_pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
1080
        try:
 
1081
            raw_conflicts = resolve_conflicts(tt, child_pb)
 
1082
        finally:
 
1083
            child_pb.finished()
1049
1084
        for line in conflicts_strings(cook_conflicts(raw_conflicts, tt)):
1050
1085
            warning(line)
 
1086
        pp.next_phase()
1051
1087
        tt.apply()
1052
1088
        working_tree.set_merge_modified({})
1053
1089
    finally: