604
604
trace.mutter('Criss-cross lcas: %r' % lcas)
605
605
if self.base_rev_id in lcas:
606
606
trace.mutter('Unable to find unique lca. '
607
'Fallback %r as best option.' % self.base_rev_id)
607
'Fallback %r as best option.'
608
609
interesting_revision_ids = set(lcas)
609
610
interesting_revision_ids.add(self.base_rev_id)
610
611
interesting_trees = dict((t.get_revision_id(), t)
1387
1389
if hook_status != 'not_applicable':
1388
1390
# Don't try any more hooks, this one applies.
1392
# If the merge ends up replacing the content of the file, we get rid of
1393
# it at the end of this method (this variable is used to track the
1394
# exceptions to this rule).
1390
1396
result = "modified"
1391
1397
if hook_status == 'not_applicable':
1392
# This is a contents conflict, because none of the available
1393
# functions could merge it.
1398
# No merge hook was able to resolve the situation. Two cases exist:
1399
# a content conflict or a duplicate one.
1395
1401
name = self.tt.final_name(trans_id)
1396
1402
parent_id = self.tt.final_parent(trans_id)
1397
if self.this_tree.has_id(file_id):
1398
self.tt.unversion_file(trans_id)
1399
file_group = self._dump_conflicts(name, parent_id, file_id,
1401
self._raw_conflicts.append(('contents conflict', file_group))
1404
inhibit_content_conflict = False
1405
if params.this_kind is None: # file_id is not in THIS
1406
# Is the name used for a different file_id ?
1407
dupe_path = self.other_tree.id2path(file_id)
1408
this_id = self.this_tree.path2id(dupe_path)
1409
if this_id is not None:
1410
# Two entries for the same path
1412
# versioning the merged file will trigger a duplicate
1414
self.tt.version_file(file_id, trans_id)
1415
transform.create_from_tree(
1416
self.tt, trans_id, self.other_tree, file_id,
1417
filter_tree_path=self._get_filter_tree_path(file_id))
1418
inhibit_content_conflict = True
1419
elif params.other_kind is None: # file_id is not in OTHER
1420
# Is the name used for a different file_id ?
1421
dupe_path = self.this_tree.id2path(file_id)
1422
other_id = self.other_tree.path2id(dupe_path)
1423
if other_id is not None:
1424
# Two entries for the same path again, but here, the other
1425
# entry will also be merged. We simply inhibit the
1426
# 'content' conflict creation because we know OTHER will
1427
# create (or has already created depending on ordering) an
1428
# entry at the same path. This will trigger a 'duplicate'
1431
inhibit_content_conflict = True
1432
if not inhibit_content_conflict:
1433
if params.this_kind is not None:
1434
self.tt.unversion_file(trans_id)
1435
# This is a contents conflict, because none of the available
1436
# functions could merge it.
1437
file_group = self._dump_conflicts(name, parent_id, file_id,
1439
self._raw_conflicts.append(('contents conflict', file_group))
1402
1440
elif hook_status == 'success':
1403
1441
self.tt.create_file(lines, trans_id)
1404
1442
elif hook_status == 'conflicted':
1420
1458
raise AssertionError('unknown hook_status: %r' % (hook_status,))
1421
1459
if not self.this_tree.has_id(file_id) and result == "modified":
1422
1460
self.tt.version_file(file_id, trans_id)
1423
# The merge has been performed, so the old contents should not be
1425
self.tt.delete_contents(trans_id)
1462
# The merge has been performed and produced a new content, so the
1463
# old contents should not be retained.
1464
self.tt.delete_contents(trans_id)
1428
1467
def _default_other_winner_merge(self, merge_hook_params):
1429
1468
"""Replace this contents with other."""
1430
1469
file_id = merge_hook_params.file_id
1431
1470
trans_id = merge_hook_params.trans_id
1432
file_in_this = self.this_tree.has_id(file_id)
1433
1471
if self.other_tree.has_id(file_id):
1434
1472
# OTHER changed the file
1436
if wt.supports_content_filtering():
1437
# We get the path from the working tree if it exists.
1438
# That fails though when OTHER is adding a file, so
1439
# we fall back to the other tree to find the path if
1440
# it doesn't exist locally.
1442
filter_tree_path = wt.id2path(file_id)
1443
except errors.NoSuchId:
1444
filter_tree_path = self.other_tree.id2path(file_id)
1446
# Skip the id2path lookup for older formats
1447
filter_tree_path = None
1448
transform.create_from_tree(self.tt, trans_id,
1449
self.other_tree, file_id,
1450
filter_tree_path=filter_tree_path)
1473
transform.create_from_tree(
1474
self.tt, trans_id, self.other_tree, file_id,
1475
filter_tree_path=self._get_filter_tree_path(file_id))
1451
1476
return 'done', None
1477
elif self.this_tree.has_id(file_id):
1453
1478
# OTHER deleted the file
1454
1479
return 'delete', None
1530
1555
file_group.append(trans_id)
1558
def _get_filter_tree_path(self, file_id):
1559
if self.this_tree.supports_content_filtering():
1560
# We get the path from the working tree if it exists.
1561
# That fails though when OTHER is adding a file, so
1562
# we fall back to the other tree to find the path if
1563
# it doesn't exist locally.
1565
return self.this_tree.id2path(file_id)
1566
except errors.NoSuchId:
1567
return self.other_tree.id2path(file_id)
1568
# Skip the id2path lookup for older formats
1532
1571
def _dump_conflicts(self, name, parent_id, file_id, this_lines=None,
1533
1572
base_lines=None, other_lines=None, set_version=False,
1534
1573
no_base=False):
1652
1691
for trans_id in conflict[1]:
1653
1692
file_id = self.tt.final_file_id(trans_id)
1654
1693
if file_id is not None:
1694
# Ok we found the relevant file-id
1656
1696
path = fp.get_path(trans_id)
1657
1697
for suffix in ('.BASE', '.THIS', '.OTHER'):
1658
1698
if path.endswith(suffix):
1699
# Here is the raw path
1659
1700
path = path[:-len(suffix)]
1661
1702
c = _mod_conflicts.Conflict.factory(conflict_type,