47
47
conflict that are not explicitly handled cause an exception and
48
48
terminate the merge.
50
def __init__(self, ignore_zero=False):
50
def __init__(self, this_tree, base_tree, other_tree, ignore_zero=False):
51
51
ExceptionConflictHandler.__init__(self)
53
53
self.ignore_zero = ignore_zero
54
self.this_tree = this_tree
55
self.base_tree = base_tree
56
self.other_tree = other_tree
55
58
def copy(self, source, dest):
56
59
"""Copy the text and mode of a file
136
139
return ReplaceContents(this_contents, None)
141
def abs_this_path(self, file_id):
142
"""Return the absolute path for a file_id in the this tree."""
143
relpath = self.this_tree.id2path(file_id)
144
return self.this_tree.tree.abspath(relpath)
146
def add_missing_parents(self, file_id, tree):
147
"""If some of the parents for file_id are missing, add them."""
148
entry = tree.tree.inventory[file_id]
149
if entry.parent_id not in self.this_tree:
150
return self.create_all_missing(entry.parent_id, tree)
152
return self.abs_this_path(entry.parent_id)
154
def create_all_missing(self, file_id, tree):
155
"""Add contents for a file_id and all its parents to a tree."""
156
entry = tree.tree.inventory[file_id]
157
if entry.parent_id is not None and entry.parent_id not in self.this_tree:
158
abspath = self.create_all_missing(entry.parent_id, tree)
160
abspath = self.abs_this_path(entry.parent_id)
161
entry_path = os.path.join(abspath, entry.name)
162
if not os.path.isdir(entry_path):
163
self.create(file_id, entry_path, tree)
166
def create(self, file_id, path, tree, reverse=False):
167
"""Uses tree data to create a filesystem object for the file_id"""
168
from merge_core import get_id_contents
169
get_id_contents(file_id, tree)(path, self, reverse)
171
def missing_for_merge(self, file_id, other_path):
172
"""The file_id doesn't exist in THIS, but does in OTHER and BASE"""
173
self.conflict("Other branch modified locally deleted file %s" %
175
parent_dir = self.add_missing_parents(file_id, self.other_tree)
176
stem = os.path.join(parent_dir, os.path.basename(other_path))
177
self.create(file_id, stem+".OTHER", self.other_tree)
178
self.create(file_id, stem+".BASE", self.base_tree)
138
180
def finalize(self):
139
181
if not self.ignore_zero:
140
182
print "%d conflicts encountered.\n" % self.conflicts
357
399
inv_changes = merge_flex(this_tree, base_tree, other_tree,
358
400
generate_cset_optimized, get_inventory,
359
MergeConflictHandler(ignore_zero=ignore_zero),
401
MergeConflictHandler(this_tree, base_tree,
402
other_tree, ignore_zero=ignore_zero),
360
403
merge_factory=merge_factory,
361
404
interesting_ids=interesting_ids)