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