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