Skip to content

Commit c008c0f

Browse files
committed
diff A...B: give one possible diff when there are more than one merge-base
We instead showed a combined diff that explains one of the randomly chosen merge-base as if it were the result of merging all the other merge bases and two tips given, which made no sense at all. An alternative is to simply fail such a request, telling the user that there are criss-cross merges, but it wouldn't be so helpful. Noticed by James Pickens. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2998138 commit c008c0f

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

builtin-diff.c

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -405,17 +405,32 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
405405
result = builtin_diff_index(&rev, argc, argv);
406406
else if (ents == 2)
407407
result = builtin_diff_tree(&rev, argc, argv, ent);
408-
else if ((ents == 3) && (ent[0].item->flags & UNINTERESTING)) {
409-
/* diff A...B where there is one sane merge base between
410-
* A and B. We have ent[0] == merge-base, ent[1] == A,
411-
* and ent[2] == B. Show diff between the base and B.
408+
else if (ent[0].item->flags & UNINTERESTING) {
409+
/*
410+
* Perhaps the user gave us A...B, which expands
411+
* to a list of negative merge bases followed by
412+
* A (symmetric-left) and B? Let's make sure...
412413
*/
413-
ent[1] = ent[2];
414+
for (i = 1; i < ents; i++)
415+
if (!(ent[i].item->flags & UNINTERESTING))
416+
break;
417+
if (ents != i + 2 ||
418+
(ent[i+1].item->flags & UNINTERESTING) ||
419+
(!(ent[i].item->flags & SYMMETRIC_LEFT)) ||
420+
(ent[i+1].item->flags & SYMMETRIC_LEFT))
421+
die("what do you mean by that?");
422+
/*
423+
* diff A...B where there is at least one merge base
424+
* between A and B. We have ent[0] == merge-base,
425+
* ent[ents-2] == A, and ent[ents-1] == B. Show diff
426+
* between the base and B. Note that we pick one
427+
* merge base at random if there are more than one.
428+
*/
429+
ent[1] = ent[ents-1];
414430
result = builtin_diff_tree(&rev, argc, argv, ent);
415-
}
416-
else
431+
} else
417432
result = builtin_diff_combined(&rev, argc, argv,
418-
ent, ents);
433+
ent, ents);
419434
result = diff_result_code(&rev.diffopt, result);
420435
if (1 < rev.diffopt.skip_stat_unmatch)
421436
refresh_index_quietly();

0 commit comments

Comments
 (0)