92
92
"""Attempt to merge the contents of a single file.
94
94
:param merge_params: A bzrlib.merge.MergeHookParams
95
:return: A tuple of (status, chunks), where status is one of
95
:return : A tuple of (status, chunks), where status is one of
96
96
'not_applicable', 'success', 'conflicted', or 'delete'. If status
97
97
is 'success' or 'conflicted', then chunks should be an iterable of
98
98
strings for the new file contents.
868
868
executable3, file_status, resolver=resolver)
870
870
child_pb.finished()
871
self.tt.fixup_new_roots()
872
872
self._finish_computing_transform()
874
874
def _finish_computing_transform(self):
888
888
self.tt.iter_changes(), self.change_reporter)
889
889
self.cook_conflicts(fs_conflicts)
890
890
for conflict in self.cooked_conflicts:
891
trace.warning(unicode(conflict))
891
trace.warning(conflict)
893
893
def _entries3(self):
894
894
"""Gather data about files modified between three trees.
933
933
it then compares with THIS and BASE.
935
935
For the multi-valued entries, the format will be (BASE, [lca1, lca2])
937
:return: [(file_id, changed, parents, names, executable)], where:
939
* file_id: Simple file_id of the entry
940
* changed: Boolean, True if the kind or contents changed else False
941
* parents: ((base, [parent_id, in, lcas]), parent_id_other,
943
* names: ((base, [name, in, lcas]), name_in_other, name_in_this)
944
* executable: ((base, [exec, in, lcas]), exec_in_other,
936
:return: [(file_id, changed, parents, names, executable)]
937
file_id Simple file_id of the entry
938
changed Boolean, True if the kind or contents changed
940
parents ((base, [parent_id, in, lcas]), parent_id_other,
942
names ((base, [name, in, lcas]), name_in_other, name_in_this)
943
executable ((base, [exec, in, lcas]), exec_in_other, exec_in_this)
947
945
if self.interesting_files is not None:
948
946
lookup_trees = [self.this_tree, self.base_tree]
991
989
lca_entries.append(lca_ie)
993
if base_inventory.has_id(file_id):
991
if file_id in base_inventory:
994
992
base_ie = base_inventory[file_id]
996
994
base_ie = _none_entry
998
if this_inventory.has_id(file_id):
996
if file_id in this_inventory:
999
997
this_ie = this_inventory[file_id]
1001
999
this_ie = _none_entry
1106
1103
other_root = self.tt.trans_id_file_id(other_root_file_id)
1107
1104
if other_root == self.tt.root:
1109
if self.this_tree.inventory.has_id(
1110
self.other_tree.inventory.root.file_id):
1111
# the other tree's root is a non-root in the current tree (as
1112
# when a previously unrelated branch is merged into another)
1106
if self.other_tree.inventory.root.file_id in self.this_tree.inventory:
1107
# the other tree's root is a non-root in the current tree (as when
1108
# a previously unrelated branch is merged into another)
1114
1110
if self.tt.final_kind(other_root) is not None:
1115
1111
other_root_is_present = True
1168
1164
def contents_sha1(tree, file_id):
1169
1165
"""Determine the sha1 of the file contents (used as a key method)."""
1170
if not tree.has_id(file_id):
1166
if file_id not in tree:
1172
1168
return tree.get_file_sha1(file_id)
1318
1314
self._raw_conflicts.append(('path conflict', trans_id, file_id,
1319
1315
this_parent, this_name,
1320
1316
other_parent, other_name))
1321
if not self.other_tree.has_id(file_id):
1317
if other_name is None:
1322
1318
# it doesn't matter whether the result was 'other' or
1323
# 'conflict'-- if it has no file id, we leave it alone.
1319
# 'conflict'-- if there's no 'other', we leave it alone.
1325
1321
parent_id = parents[self.winner_idx[parent_id_winner]]
1326
name = names[self.winner_idx[name_winner]]
1327
if parent_id is not None or name is not None:
1322
if parent_id is not None:
1328
1323
# if we get here, name_winner and parent_winner are set to safe
1330
if parent_id is None and name is not None:
1331
# if parent_id is None and name is non-None, current file is
1333
if names[self.winner_idx[parent_id_winner]] != '':
1334
raise AssertionError(
1335
'File looks like a root, but named %s' %
1336
names[self.winner_idx[parent_id_winner]])
1337
parent_trans_id = transform.ROOT_PARENT
1339
parent_trans_id = self.tt.trans_id_file_id(parent_id)
1340
self.tt.adjust_path(name, parent_trans_id,
1325
self.tt.adjust_path(names[self.winner_idx[name_winner]],
1326
self.tt.trans_id_file_id(parent_id),
1341
1327
self.tt.trans_id_file_id(file_id))
1343
1329
def _do_merge_contents(self, file_id):
1344
1330
"""Performs a merge on file_id contents."""
1345
1331
def contents_pair(tree):
1346
if not tree.has_id(file_id):
1332
if file_id not in tree:
1347
1333
return (None, None)
1348
1334
kind = tree.kind(file_id)
1349
1335
if kind == "file":
1618
1604
def cook_conflicts(self, fs_conflicts):
1619
1605
"""Convert all conflicts into a form that doesn't depend on trans_id"""
1620
content_conflict_file_ids = set()
1621
cooked_conflicts = transform.cook_conflicts(fs_conflicts, self.tt)
1606
self.cooked_conflicts.extend(transform.cook_conflicts(
1607
fs_conflicts, self.tt))
1622
1608
fp = transform.FinalPaths(self.tt)
1623
1609
for conflict in self._raw_conflicts:
1624
1610
conflict_type = conflict[0]
1635
1621
if other_parent is None or other_name is None:
1636
1622
other_path = '<deleted>'
1638
if other_parent == self.other_tree.get_root_id():
1639
# The tree transform doesn't know about the other root,
1640
# so we special case here to avoid a NoFinalPath
1644
parent_path = fp.get_path(
1645
self.tt.trans_id_file_id(other_parent))
1624
parent_path = fp.get_path(
1625
self.tt.trans_id_file_id(other_parent))
1646
1626
other_path = osutils.pathjoin(parent_path, other_name)
1647
1627
c = _mod_conflicts.Conflict.factory(
1648
1628
'path conflict', path=this_path,
1661
1641
c = _mod_conflicts.Conflict.factory(conflict_type,
1662
1642
path=path, file_id=file_id)
1663
content_conflict_file_ids.add(file_id)
1664
1643
elif conflict_type == 'text conflict':
1665
1644
trans_id = conflict[1]
1666
1645
path = fp.get_path(trans_id)
1669
1648
path=path, file_id=file_id)
1671
1650
raise AssertionError('bad conflict type: %r' % (conflict,))
1672
cooked_conflicts.append(c)
1674
self.cooked_conflicts = []
1675
# We want to get rid of path conflicts when a corresponding contents
1676
# conflict exists. This can occur when one branch deletes a file while
1677
# the other renames *and* modifies it. In this case, the content
1678
# conflict is enough.
1679
for c in cooked_conflicts:
1680
if (c.typestring == 'path conflict'
1681
and c.file_id in content_conflict_file_ids):
1683
1651
self.cooked_conflicts.append(c)
1684
1652
self.cooked_conflicts.sort(key=_mod_conflicts.Conflict.sort_key)
1930
1898
name_in_target = osutils.basename(self._target_subdir)
1931
1899
merge_into_root = subdir.copy()
1932
1900
merge_into_root.name = name_in_target
1933
if self.this_tree.inventory.has_id(merge_into_root.file_id):
1901
if merge_into_root.file_id in self.this_tree.inventory:
1934
1902
# Give the root a new file-id.
1935
1903
# This can happen fairly easily if the directory we are
1936
1904
# incorporating is the root, and both trees have 'TREE_ROOT' as
1974
1942
if this_tree is None:
1975
1943
raise errors.BzrError("bzrlib.merge.merge_inner requires a this_tree "
1944
"parameter as of bzrlib version 0.8.")
1977
1945
merger = Merger(this_branch, other_tree, base_tree, this_tree=this_tree,
1978
1946
pb=pb, change_reporter=change_reporter)
1979
1947
merger.backup_files = backup_files
2433
2401
class _PlanLCAMerge(_PlanMergeBase):
2435
2403
This merge algorithm differs from _PlanMerge in that:
2437
2404
1. comparisons are done against LCAs only
2438
2405
2. cases where a contested line is new versus one LCA but old versus
2439
2406
another are marked as conflicts, by emitting the line as conflicted-a
2481
2448
If a line is killed and new, this indicates that the two merge
2482
2449
revisions contain differing conflict resolutions.
2484
2450
:param revision_id: The id of the revision in which the lines are
2486
2452
:param unique_line_numbers: The line numbers of unique lines.
2487
:return: a tuple of (new_this, killed_other)
2453
:return a tuple of (new_this, killed_other):