@@ -196,6 +196,15 @@ static int collect_merge_info_callback(int n,
unsigned mbase_null = !(mask & 1);
unsigned side1_null = !(mask & 2);
unsigned side2_null = !(mask & 4);
+ unsigned side1_matches_mbase = (!side1_null && !mbase_null &&
+ names[0].mode == names[1].mode &&
+ oideq(&names[0].oid, &names[1].oid));
+ unsigned side2_matches_mbase = (!side2_null && !mbase_null &&
+ names[0].mode == names[2].mode &&
+ oideq(&names[0].oid, &names[2].oid));
+ unsigned sides_match = (!side1_null && !side2_null &&
+ names[1].mode == names[2].mode &&
+ oideq(&names[1].oid, &names[2].oid));
/* n = 3 is a fundamental assumption. */
if (n != 3)
@@ -248,10 +257,19 @@ static int collect_merge_info_callback(int n,
newinfo.pathlen = st_add3(newinfo.pathlen, p->pathlen, 1);
for (i = 0; i < 3; i++) {
- const struct object_id *oid = NULL;
- if (dirmask & 1)
- oid = &names[i].oid;
- buf[i] = fill_tree_descriptor(opt->repo, t + i, oid);
+ if (i == 1 && side1_matches_mbase)
+ t[1] = t[0];
+ else if (i == 2 && side2_matches_mbase)
+ t[2] = t[0];
+ else if (i == 2 && sides_match)
+ t[2] = t[1];
+ else {
+ const struct object_id *oid = NULL;
+ if (dirmask & 1)
+ oid = &names[i].oid;
+ buf[i] = fill_tree_descriptor(opt->repo,
+ t + i, oid);
+ }
dirmask >>= 1;
}