Skip to content

Commit 4cd1b99

Browse files
committed
Merge branch 'jc/diff-merge-base-multi'
* jc/diff-merge-base-multi: diff A...B: give one possible diff when there are more than one merge-base
2 parents a8b7fcf + c008c0f commit 4cd1b99

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
@@ -407,17 +407,32 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
407407
result = builtin_diff_index(&rev, argc, argv);
408408
else if (ents == 2)
409409
result = builtin_diff_tree(&rev, argc, argv, ent);
410-
else if ((ents == 3) && (ent[0].item->flags & UNINTERESTING)) {
411-
/* diff A...B where there is one sane merge base between
412-
* A and B. We have ent[0] == merge-base, ent[1] == A,
413-
* and ent[2] == B. Show diff between the base and B.
410+
else if (ent[0].item->flags & UNINTERESTING) {
411+
/*
412+
* Perhaps the user gave us A...B, which expands
413+
* to a list of negative merge bases followed by
414+
* A (symmetric-left) and B? Let's make sure...
414415
*/
415-
ent[1] = ent[2];
416+
for (i = 1; i < ents; i++)
417+
if (!(ent[i].item->flags & UNINTERESTING))
418+
break;
419+
if (ents != i + 2 ||
420+
(ent[i+1].item->flags & UNINTERESTING) ||
421+
(!(ent[i].item->flags & SYMMETRIC_LEFT)) ||
422+
(ent[i+1].item->flags & SYMMETRIC_LEFT))
423+
die("what do you mean by that?");
424+
/*
425+
* diff A...B where there is at least one merge base
426+
* between A and B. We have ent[0] == merge-base,
427+
* ent[ents-2] == A, and ent[ents-1] == B. Show diff
428+
* between the base and B. Note that we pick one
429+
* merge base at random if there are more than one.
430+
*/
431+
ent[1] = ent[ents-1];
416432
result = builtin_diff_tree(&rev, argc, argv, ent);
417-
}
418-
else
433+
} else
419434
result = builtin_diff_combined(&rev, argc, argv,
420-
ent, ents);
435+
ent, ents);
421436
result = diff_result_code(&rev.diffopt, result);
422437
if (1 < rev.diffopt.skip_stat_unmatch)
423438
refresh_index_quietly();

0 commit comments

Comments
 (0)