1017
1017
raise AssertionError('unhandled kind: %s' % other_ie.kind)
1018
# XXX: We need to handle kind == 'symlink'
1020
1019
# If we have gotten this far, that means something has changed
1021
1020
result.append((file_id, content_changed,
1112
1111
def _three_way(base, other, this):
1113
#if base == other, either they all agree, or only THIS has changed.
1114
1112
if base == other:
1113
# if 'base == other', either they all agree, or only 'this' has
1116
1116
elif this not in (base, other):
1117
# 'this' is neither 'base' nor 'other', so both sides changed
1117
1118
return 'conflict'
1118
# "Ambiguous clean merge" -- both sides have made the same change.
1119
1119
elif this == other:
1120
# "Ambiguous clean merge" -- both sides have made the same change.
1121
# this == base: only other has changed.
1123
# this == base: only other has changed.
1229
1230
parent_id_winner = "other"
1230
1231
if name_winner == "this" and parent_id_winner == "this":
1232
if name_winner == "conflict":
1233
trans_id = self.tt.trans_id_file_id(file_id)
1234
self._raw_conflicts.append(('name conflict', trans_id,
1235
this_name, other_name))
1236
if parent_id_winner == "conflict":
1237
trans_id = self.tt.trans_id_file_id(file_id)
1238
self._raw_conflicts.append(('parent conflict', trans_id,
1239
this_parent, other_parent))
1233
if name_winner == 'conflict' or parent_id_winner == 'conflict':
1234
# Creating helpers (.OTHER or .THIS) here cause problems down the
1235
# road if a ContentConflict needs to be created so we should not do
1237
trans_id = self.tt.trans_id_file_id(file_id)
1238
self._raw_conflicts.append(('path conflict', trans_id, file_id,
1239
this_parent, this_name,
1240
other_parent, other_name))
1240
1241
if other_name is None:
1241
1242
# it doesn't matter whether the result was 'other' or
1242
1243
# 'conflict'-- if there's no 'other', we leave it alone.
1244
# if we get here, name_winner and parent_winner are set to safe values.
1245
trans_id = self.tt.trans_id_file_id(file_id)
1246
1245
parent_id = parents[self.winner_idx[parent_id_winner]]
1247
1246
if parent_id is not None:
1248
parent_trans_id = self.tt.trans_id_file_id(parent_id)
1247
# if we get here, name_winner and parent_winner are set to safe
1249
1249
self.tt.adjust_path(names[self.winner_idx[name_winner]],
1250
parent_trans_id, trans_id)
1250
self.tt.trans_id_file_id(parent_id),
1251
self.tt.trans_id_file_id(file_id))
1252
1253
def _do_merge_contents(self, file_id):
1253
1254
"""Performs a merge on file_id contents."""
1533
1534
def cook_conflicts(self, fs_conflicts):
1534
1535
"""Convert all conflicts into a form that doesn't depend on trans_id"""
1536
1536
self.cooked_conflicts.extend(transform.cook_conflicts(
1537
1537
fs_conflicts, self.tt))
1538
1538
fp = transform.FinalPaths(self.tt)
1539
1539
for conflict in self._raw_conflicts:
1540
1540
conflict_type = conflict[0]
1541
if conflict_type in ('name conflict', 'parent conflict'):
1542
trans_id = conflict[1]
1543
conflict_args = conflict[2:]
1544
if trans_id not in name_conflicts:
1545
name_conflicts[trans_id] = {}
1546
transform.unique_add(name_conflicts[trans_id], conflict_type,
1548
if conflict_type == 'contents conflict':
1541
if conflict_type == 'path conflict':
1543
this_parent, this_name,
1544
other_parent, other_name) = conflict[1:]
1545
if this_parent is None or this_name is None:
1546
this_path = '<deleted>'
1548
parent_path = fp.get_path(
1549
self.tt.trans_id_file_id(this_parent))
1550
this_path = osutils.pathjoin(parent_path, this_name)
1551
if other_parent is None or other_name is None:
1552
other_path = '<deleted>'
1554
parent_path = fp.get_path(
1555
self.tt.trans_id_file_id(other_parent))
1556
other_path = osutils.pathjoin(parent_path, other_name)
1557
c = _mod_conflicts.Conflict.factory(
1558
'path conflict', path=this_path,
1559
conflict_path=other_path,
1561
elif conflict_type == 'contents conflict':
1549
1562
for trans_id in conflict[1]:
1550
1563
file_id = self.tt.final_file_id(trans_id)
1551
1564
if file_id is not None:
1558
1571
c = _mod_conflicts.Conflict.factory(conflict_type,
1559
1572
path=path, file_id=file_id)
1560
self.cooked_conflicts.append(c)
1561
if conflict_type == 'text conflict':
1573
elif conflict_type == 'text conflict':
1562
1574
trans_id = conflict[1]
1563
1575
path = fp.get_path(trans_id)
1564
1576
file_id = self.tt.final_file_id(trans_id)
1565
1577
c = _mod_conflicts.Conflict.factory(conflict_type,
1566
1578
path=path, file_id=file_id)
1567
self.cooked_conflicts.append(c)
1569
for trans_id, conflicts in name_conflicts.iteritems():
1571
this_parent, other_parent = conflicts['parent conflict']
1572
if this_parent == other_parent:
1573
raise AssertionError()
1575
this_parent = other_parent = \
1576
self.tt.final_file_id(self.tt.final_parent(trans_id))
1578
this_name, other_name = conflicts['name conflict']
1579
if this_name == other_name:
1580
raise AssertionError()
1582
this_name = other_name = self.tt.final_name(trans_id)
1583
other_path = fp.get_path(trans_id)
1584
if this_parent is not None and this_name is not None:
1585
this_parent_path = \
1586
fp.get_path(self.tt.trans_id_file_id(this_parent))
1587
this_path = osutils.pathjoin(this_parent_path, this_name)
1589
this_path = "<deleted>"
1590
file_id = self.tt.final_file_id(trans_id)
1591
c = _mod_conflicts.Conflict.factory('path conflict', path=this_path,
1592
conflict_path=other_path,
1580
raise AssertionError('bad conflict type: %r' % (conflict,))
1594
1581
self.cooked_conflicts.append(c)
1595
1582
self.cooked_conflicts.sort(key=_mod_conflicts.Conflict.sort_key)