138
140
params.winner == 'other' or
139
141
# THIS and OTHER aren't both files.
140
142
not params.is_file_merge() or
141
# The filename doesn't match *.xml
143
# The filename doesn't match
142
144
not self.file_matches(params)):
143
145
return 'not_applicable', None
144
146
return self.merge_matching(params)
604
606
trace.mutter('Criss-cross lcas: %r' % lcas)
605
607
if self.base_rev_id in lcas:
606
608
trace.mutter('Unable to find unique lca. '
607
'Fallback %r as best option.' % self.base_rev_id)
609
'Fallback %r as best option.'
608
611
interesting_revision_ids = set(lcas)
609
612
interesting_revision_ids.add(self.base_rev_id)
610
613
interesting_trees = dict((t.get_revision_id(), t)
711
715
merge = operation.run_simple()
712
716
if len(merge.cooked_conflicts) == 0:
713
717
if not self.ignore_zero and not trace.is_quiet():
714
trace.note("All changes applied successfully.")
718
trace.note(gettext("All changes applied successfully."))
716
trace.note("%d conflicts encountered."
720
trace.note(gettext("%d conflicts encountered.")
717
721
% len(merge.cooked_conflicts))
719
723
return len(merge.cooked_conflicts)
852
856
entries = self._entries_lca()
853
857
resolver = self._lca_multi_way
858
# Prepare merge hooks
859
factories = Merger.hooks['merge_file_content']
860
# One hook for each registered one plus our default merger
861
hooks = [factory(self) for factory in factories] + [self]
862
self.active_hooks = [hook for hook in hooks if hook is not None]
854
863
child_pb = ui.ui_factory.nested_progress_bar()
856
factories = Merger.hooks['merge_file_content']
857
hooks = [factory(self) for factory in factories] + [self]
858
self.active_hooks = [hook for hook in hooks if hook is not None]
859
865
for num, (file_id, changed, parents3, names3,
860
866
executable3) in enumerate(entries):
861
child_pb.update('Preparing file merge', num, len(entries))
867
# Try merging each entry
868
child_pb.update(gettext('Preparing file merge'),
862
870
self._merge_names(file_id, parents3, names3, resolver=resolver)
864
872
file_status = self._do_merge_contents(file_id)
1387
1395
if hook_status != 'not_applicable':
1388
1396
# Don't try any more hooks, this one applies.
1398
# If the merge ends up replacing the content of the file, we get rid of
1399
# it at the end of this method (this variable is used to track the
1400
# exceptions to this rule).
1390
1402
result = "modified"
1391
1403
if hook_status == 'not_applicable':
1392
# This is a contents conflict, because none of the available
1393
# functions could merge it.
1404
# No merge hook was able to resolve the situation. Two cases exist:
1405
# a content conflict or a duplicate one.
1395
1407
name = self.tt.final_name(trans_id)
1396
1408
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))
1410
inhibit_content_conflict = False
1411
if params.this_kind is None: # file_id is not in THIS
1412
# Is the name used for a different file_id ?
1413
dupe_path = self.other_tree.id2path(file_id)
1414
this_id = self.this_tree.path2id(dupe_path)
1415
if this_id is not None:
1416
# Two entries for the same path
1418
# versioning the merged file will trigger a duplicate
1420
self.tt.version_file(file_id, trans_id)
1421
transform.create_from_tree(
1422
self.tt, trans_id, self.other_tree, file_id,
1423
filter_tree_path=self._get_filter_tree_path(file_id))
1424
inhibit_content_conflict = True
1425
elif params.other_kind is None: # file_id is not in OTHER
1426
# Is the name used for a different file_id ?
1427
dupe_path = self.this_tree.id2path(file_id)
1428
other_id = self.other_tree.path2id(dupe_path)
1429
if other_id is not None:
1430
# Two entries for the same path again, but here, the other
1431
# entry will also be merged. We simply inhibit the
1432
# 'content' conflict creation because we know OTHER will
1433
# create (or has already created depending on ordering) an
1434
# entry at the same path. This will trigger a 'duplicate'
1437
inhibit_content_conflict = True
1438
if not inhibit_content_conflict:
1439
if params.this_kind is not None:
1440
self.tt.unversion_file(trans_id)
1441
# This is a contents conflict, because none of the available
1442
# functions could merge it.
1443
file_group = self._dump_conflicts(name, parent_id, file_id,
1445
self._raw_conflicts.append(('contents conflict', file_group))
1402
1446
elif hook_status == 'success':
1403
1447
self.tt.create_file(lines, trans_id)
1404
1448
elif hook_status == 'conflicted':
1420
1464
raise AssertionError('unknown hook_status: %r' % (hook_status,))
1421
1465
if not self.this_tree.has_id(file_id) and result == "modified":
1422
1466
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)
1468
# The merge has been performed and produced a new content, so the
1469
# old contents should not be retained.
1470
self.tt.delete_contents(trans_id)
1428
1473
def _default_other_winner_merge(self, merge_hook_params):
1429
1474
"""Replace this contents with other."""
1430
1475
file_id = merge_hook_params.file_id
1431
1476
trans_id = merge_hook_params.trans_id
1432
file_in_this = self.this_tree.has_id(file_id)
1433
1477
if self.other_tree.has_id(file_id):
1434
1478
# 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)
1479
transform.create_from_tree(
1480
self.tt, trans_id, self.other_tree, file_id,
1481
filter_tree_path=self._get_filter_tree_path(file_id))
1451
1482
return 'done', None
1483
elif self.this_tree.has_id(file_id):
1453
1484
# OTHER deleted the file
1454
1485
return 'delete', None
1530
1561
file_group.append(trans_id)
1564
def _get_filter_tree_path(self, file_id):
1565
if self.this_tree.supports_content_filtering():
1566
# We get the path from the working tree if it exists.
1567
# That fails though when OTHER is adding a file, so
1568
# we fall back to the other tree to find the path if
1569
# it doesn't exist locally.
1571
return self.this_tree.id2path(file_id)
1572
except errors.NoSuchId:
1573
return self.other_tree.id2path(file_id)
1574
# Skip the id2path lookup for older formats
1532
1577
def _dump_conflicts(self, name, parent_id, file_id, this_lines=None,
1533
1578
base_lines=None, other_lines=None, set_version=False,
1534
1579
no_base=False):
1635
1680
if other_parent is None or other_name is None:
1636
1681
other_path = '<deleted>'
1638
parent_path = fp.get_path(
1639
self.tt.trans_id_file_id(other_parent))
1683
if other_parent == self.other_tree.get_root_id():
1684
# The tree transform doesn't know about the other root,
1685
# so we special case here to avoid a NoFinalPath
1689
parent_path = fp.get_path(
1690
self.tt.trans_id_file_id(other_parent))
1640
1691
other_path = osutils.pathjoin(parent_path, other_name)
1641
1692
c = _mod_conflicts.Conflict.factory(
1642
1693
'path conflict', path=this_path,
1646
1697
for trans_id in conflict[1]:
1647
1698
file_id = self.tt.final_file_id(trans_id)
1648
1699
if file_id is not None:
1700
# Ok we found the relevant file-id
1650
1702
path = fp.get_path(trans_id)
1651
1703
for suffix in ('.BASE', '.THIS', '.OTHER'):
1652
1704
if path.endswith(suffix):
1705
# Here is the raw path
1653
1706
path = path[:-len(suffix)]
1655
1708
c = _mod_conflicts.Conflict.factory(conflict_type,
1900
1953
entries = self._entries_to_incorporate()
1901
1954
entries = list(entries)
1902
1955
for num, (entry, parent_id) in enumerate(entries):
1903
child_pb.update('Preparing file merge', num, len(entries))
1956
child_pb.update(gettext('Preparing file merge'), num, len(entries))
1904
1957
parent_trans_id = self.tt.trans_id_file_id(parent_id)
1905
1958
trans_id = transform.new_by_entry(self.tt, entry,
1906
1959
parent_trans_id, self.other_tree)
1990
2043
merger.set_base_revision(get_revision_id(), this_branch)
1991
2044
return merger.do_merge()
2047
merge_type_registry = registry.Registry()
2048
merge_type_registry.register('diff3', Diff3Merger,
2049
"Merge using external diff3.")
2050
merge_type_registry.register('lca', LCAMerger,
2051
"LCA-newness merge.")
2052
merge_type_registry.register('merge3', Merge3Merger,
2053
"Native diff3-style merge.")
2054
merge_type_registry.register('weave', WeaveMerger,
2055
"Weave-based merge.")
1993
2058
def get_merge_type_registry():
1994
"""Merge type registry is in bzrlib.option to avoid circular imports.
2059
"""Merge type registry was previously in bzrlib.option
1996
This method provides a sanctioned way to retrieve it.
2061
This method provides a backwards compatible way to retrieve it.
1998
from bzrlib import option
1999
return option._merge_type_registry
2063
return merge_type_registry
2002
2066
def _plan_annotate_merge(annotated_a, annotated_b, ancestors_a, ancestors_b):