665
666
raise MalformedTransform(conflicts=conflicts)
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()
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)
670
677
self._tree._write_inventory(inv)
671
678
self.__done = True
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:
696
os.rename(full_path, self._limbo_name(trans_id))
698
if e.errno != errno.ENOENT:
700
if trans_id in self._removed_id:
701
if trans_id == self._new_root:
702
file_id = self._tree.inventory.root.file_id
695
child_pb = bzrlib.ui.ui_factory.nested_progress_bar()
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 \
706
os.rename(full_path, self._limbo_name(trans_id))
708
if e.errno != errno.ENOENT:
710
if trans_id in self._removed_id:
711
if trans_id == self._new_root:
712
file_id = self._tree.inventory.root.file_id
714
file_id = self.tree_file_id(trans_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)
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]
718
if file_id is not None:
719
limbo_inv[trans_id] = inv[file_id]
713
724
def _apply_insertions(self, inv, limbo_inv):
714
725
"""Perform tree operations that insert directory/inventory names.
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))
725
kind = self._new_contents[trans_id]
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()
735
for num, (path, trans_id) in enumerate(new_paths):
736
child_pb.update('adding file', num, len(new_paths))
731
os.rename(self._limbo_name(trans_id), full_path)
733
# We may be renaming a dangling inventory id
734
if e.errno != errno.ENOENT:
736
if trans_id in self._new_contents:
737
modified_paths.append(full_path)
738
del self._new_contents[trans_id]
740
if trans_id in self._new_id:
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)
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)
738
kind = self._new_contents[trans_id]
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)
745
os.rename(self._limbo_name(trans_id), full_path)
747
# We may be renaming a dangling inventory id
748
if e.errno != errno.ENOENT:
750
if trans_id in self._new_contents:
751
modified_paths.append(full_path)
752
del self._new_contents[trans_id]
754
if trans_id in self._new_id:
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\
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)
765
self._tree.inventory.path2id(parent_path)
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)
756
773
return modified_paths
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)
1040
pp = ProgressPhase("Revert phase", 4, pb)
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
1033
backup_this = backups
1034
if file_id in merge_modified:
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()
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
1055
backup_this = backups
1056
if file_id in merge_modified:
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)
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()
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]
1079
child_pb = bzrlib.ui.ui_factory.nested_progress_bar()
1081
raw_conflicts = resolve_conflicts(tt, child_pb)
1049
1084
for line in conflicts_strings(cook_conflicts(raw_conflicts, tt)):
1052
1088
working_tree.set_merge_modified({})