reduce_heads(): protect from duplicate input
Because we do not try computing merge base with itself for obvious reasons, the code was not prepared for an arguably insane case of the caller feeding the same commit twice to it. Noticed and test written by Sverre Hvammen Johansen Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Jul 14, 2008 at 00:09 UTC
711f6b295cf463aae07eb76e009faed3d3699623
2 files changed
+31
-2
commit.c
+9
-2
@@ -745,15 +745,22 @@ struct commit_list *reduce_heads(struct commit_list *heads)
745
for (p = heads; p; p = p->next) {
746
struct commit_list *q, *base;
747
748
+ /* Do we already have this in the result? */
749
+ for (q = result; q; q = q->next)
750
+ if (p->item == q->item)
751
+ break;
752
+ if (q)
753
+ continue;
754
+
755
num_other = 0;
756
for (q = heads; q; q = q->next) {
757
if (p->item == q->item)
758
continue;
759
other[num_other++] = q->item;
760
}
754
- if (num_other) {
761
+ if (num_other)
762
base = get_merge_bases_many(p->item, num_other, other, 1);
756
- } else
763
+ else
764
base = NULL;
765
/*
766
* If p->item does not have anything common with other
t/t7600-merge.sh
+22
@@ -490,4 +490,26 @@ test_expect_success 'merge c1 with c0, c2, c0, and c1' '
490
491
test_debug 'gitk --all'
492
493
+test_expect_success 'merge c1 with c0, c2, c0, and c1' '
494
+ git reset --hard c1 &&
495
+ git config branch.master.mergeoptions "" &&
496
+ test_tick &&
497
+ git merge c0 c2 c0 c1 &&
498
+ verify_merge file result.1-5 &&
499
+ verify_parents $c1 $c2
500
+'
501
+
502
+test_debug 'gitk --all'
503
+
504
+test_expect_success 'merge c1 with c1 and c2' '
505
+ git reset --hard c1 &&
506
+ git config branch.master.mergeoptions "" &&
507
+ test_tick &&
508
+ git merge c1 c2 &&
509
+ verify_merge file result.1-5 &&
510
+ verify_parents $c1 $c2
511
+'
512
+
513
+test_debug 'gitk --all'
514
+
515
test_done