604
605
trace.mutter('Criss-cross lcas: %r' % lcas)
605
606
if self.base_rev_id in lcas:
606
607
trace.mutter('Unable to find unique lca. '
607
'Fallback %r as best option.' % self.base_rev_id)
608
'Fallback %r as best option.'
608
610
interesting_revision_ids = set(lcas)
609
611
interesting_revision_ids.add(self.base_rev_id)
610
612
interesting_trees = dict((t.get_revision_id(), t)
711
714
merge = operation.run_simple()
712
715
if len(merge.cooked_conflicts) == 0:
713
716
if not self.ignore_zero and not trace.is_quiet():
714
trace.note("All changes applied successfully.")
717
trace.note(gettext("All changes applied successfully."))
716
trace.note("%d conflicts encountered."
719
trace.note(gettext("%d conflicts encountered.")
717
720
% len(merge.cooked_conflicts))
719
722
return len(merge.cooked_conflicts)
858
861
self.active_hooks = [hook for hook in hooks if hook is not None]
859
862
for num, (file_id, changed, parents3, names3,
860
863
executable3) in enumerate(entries):
861
child_pb.update('Preparing file merge', num, len(entries))
864
child_pb.update(gettext('Preparing file merge'), num, len(entries))
862
865
self._merge_names(file_id, parents3, names3, resolver=resolver)
864
867
file_status = self._do_merge_contents(file_id)
1387
1390
if hook_status != 'not_applicable':
1388
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).
1390
1397
result = "modified"
1391
1398
if hook_status == 'not_applicable':
1392
# This is a contents conflict, because none of the available
1393
# 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.
1395
1402
name = self.tt.final_name(trans_id)
1396
1403
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))
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))
1402
1441
elif hook_status == 'success':
1403
1442
self.tt.create_file(lines, trans_id)
1404
1443
elif hook_status == 'conflicted':
1420
1459
raise AssertionError('unknown hook_status: %r' % (hook_status,))
1421
1460
if not self.this_tree.has_id(file_id) and result == "modified":
1422
1461
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)
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)
1428
1468
def _default_other_winner_merge(self, merge_hook_params):
1429
1469
"""Replace this contents with other."""
1430
1470
file_id = merge_hook_params.file_id
1431
1471
trans_id = merge_hook_params.trans_id
1432
file_in_this = self.this_tree.has_id(file_id)
1433
1472
if self.other_tree.has_id(file_id):
1434
1473
# 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)
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))
1451
1477
return 'done', None
1478
elif self.this_tree.has_id(file_id):
1453
1479
# OTHER deleted the file
1454
1480
return 'delete', None
1530
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
1532
1572
def _dump_conflicts(self, name, parent_id, file_id, this_lines=None,
1533
1573
base_lines=None, other_lines=None, set_version=False,
1534
1574
no_base=False):
1652
1692
for trans_id in conflict[1]:
1653
1693
file_id = self.tt.final_file_id(trans_id)
1654
1694
if file_id is not None:
1695
# Ok we found the relevant file-id
1656
1697
path = fp.get_path(trans_id)
1657
1698
for suffix in ('.BASE', '.THIS', '.OTHER'):
1658
1699
if path.endswith(suffix):
1700
# Here is the raw path
1659
1701
path = path[:-len(suffix)]
1661
1703
c = _mod_conflicts.Conflict.factory(conflict_type,
1906
1948
entries = self._entries_to_incorporate()
1907
1949
entries = list(entries)
1908
1950
for num, (entry, parent_id) in enumerate(entries):
1909
child_pb.update('Preparing file merge', num, len(entries))
1951
child_pb.update(gettext('Preparing file merge'), num, len(entries))
1910
1952
parent_trans_id = self.tt.trans_id_file_id(parent_id)
1911
1953
trans_id = transform.new_by_entry(self.tt, entry,
1912
1954
parent_trans_id, self.other_tree)