merge: fix incorrect rename detection for empty files.

When merging trees containing multiple empty files, make sure a rename
is not detected between each empty files.

For example
Ancestor has files:
 * foo.c with content
 * bar.c empty

Ours has:
 * foo.c with content
 * boo.c empty

Theirs has:
 * foo.c with other content
 * bar.c with content

merge_trees() will incorrectly apply the content of theirs's 'bar.c' in
ours's boo.c' thinking 'bar.c' has been renamed to 'boo.c'.
This happens because both are empty and their sha1 are the same. Thus
merge_diff_mark_similarity_exact() incorrectly mark it as renamed.

Signed-off-by: Gregory Herrero <gregory.herrero@oracle.com>
This commit is contained in:
Gregory Herrero
2024-01-15 14:14:39 +01:00
parent 25e2b9d8c2
commit 216f698eb2

View File

@@ -1225,6 +1225,13 @@ static int merge_diff_mark_similarity_exact(
if (!GIT_MERGE_INDEX_ENTRY_EXISTS(conflict_src->ancestor_entry))
continue;
/*
* Ignore empty files because it has always the same blob sha1
* and will lead to incorrect matches between all entries.
*/
if (git_oid_equal(&conflict_src->ancestor_entry.id, &git_oid__empty_blob_sha1))
continue;
if (!GIT_MERGE_INDEX_ENTRY_EXISTS(conflict_src->our_entry)) {
error = deletes_by_oid_enqueue(ours_deletes_by_oid, &diff_list->pool, &conflict_src->ancestor_entry.id, i);
if (error < 0)