Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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>
  • Loading branch information...
commit 711f6b295cf463aae07eb76e009faed3d3699623 1 parent 3d1dd47
Junio C Hamano gitster authored

Showing 2 changed files with 31 additions and 2 deletions. Show diff stats Hide diff stats

  1. +9 2 commit.c
  2. +22 0 t/t7600-merge.sh
11 commit.c
@@ -745,15 +745,22 @@ struct commit_list *reduce_heads(struct commit_list *heads)
745 745 for (p = heads; p; p = p->next) {
746 746 struct commit_list *q, *base;
747 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 +
748 755 num_other = 0;
749 756 for (q = heads; q; q = q->next) {
750 757 if (p->item == q->item)
751 758 continue;
752 759 other[num_other++] = q->item;
753 760 }
754   - if (num_other) {
  761 + if (num_other)
755 762 base = get_merge_bases_many(p->item, num_other, other, 1);
756   - } else
  763 + else
757 764 base = NULL;
758 765 /*
759 766 * If p->item does not have anything common with other
22 t/t7600-merge.sh
@@ -490,4 +490,26 @@ test_expect_success 'merge c1 with c0, c2, c0, and c1' '
490 490
491 491 test_debug 'gitk --all'
492 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 +
493 515 test_done

0 comments on commit 711f6b2

Please sign in to comment.
Something went wrong with that request. Please try again.