121
class ThreeWayConflict(Exception):
122
def __init__(self, this, base, other):
126
msg = "Conflict merging %s %s and %s" % (this, base, other)
127
Exception.__init__(self, msg)
129
def threeway_select(this, base, other):
130
"""Returns a value selected by the three-way algorithm.
131
Raises ThreewayConflict if the algorithm yields a conflict"""
139
raise ThreeWayConflict(this, base, other)
121
142
def make_merged_entry(entry, this, base, other, conflict_handler):
122
143
from bzrlib.trace import mutter
123
144
def entry_data(file_id, tree):
134
155
other_name, other_parent, other_dir = entry_data(entry.id, other)
135
156
mutter("Dirs: this, base, other %r %r %r" % (this_dir, base_dir, other_dir))
136
157
mutter("Names: this, base, other %r %r %r" % (this_name, base_name, other_name))
137
if base_name == other_name:
141
if this_name != base_name and this_name != other_name:
142
conflict_handler.rename_conflict(entry.id, this_name, base_name,
146
new_name = other_name
148
if base_parent == other_parent:
149
old_parent = this_parent
150
new_parent = this_parent
154
if this_parent != base_parent and this_parent != other_parent:
155
conflict_handler.move_conflict(entry.id, this_dir, base_dir,
158
old_parent = this_parent
160
new_parent = other_parent
162
if old_name is not None and old_parent is not None:
163
old_path = os.path.join(old_dir, old_name)
160
new_name = threeway_select(this_name, base_name, other_name)
161
except ThreeWayConflict:
162
new_name = conflict_handler.rename_conflict(entry.id, this_name,
163
base_name, other_name)
165
old_parent = this_parent
167
new_parent = threeway_select(this_parent, base_parent, other_parent)
168
except ThreeWayConflict:
169
new_parent = conflict_handler.move_conflict(entry.id, this_dir,
171
def get_path(name, parent):
172
if name is not None and parent is not None:
173
parent_dir = {this_parent: this_dir, other_parent: other_dir,
174
base_parent: base_dir}
175
directory = parent_dir[parent]
176
return os.path.join(directory, name)
178
assert name is None and parent is None
181
old_path = get_path(old_name, old_parent)
166
183
new_entry = changeset.ChangesetEntry(entry.id, old_parent, old_path)
167
if new_name is not None and new_parent is not None:
168
new_entry.new_path = os.path.join(new_dir, new_name)
170
new_entry.new_path = None
184
new_entry.new_path = get_path(new_name, new_parent)
171
185
new_entry.new_parent = new_parent
172
186
mutter(repr(new_entry))