# [PATCH] Fix reduce_heads

4 messages from 2008-07-14 to 2008-07-14. Participants: Sverre Hvammen Johansen, Johannes Schindelin, Miklos Vajna.
Thread: https://gitlist.dev/t/14442

## Sverre Hvammen Johansen, 2008-07-14 04:07

Subject: [PATCH] Fix reduce_heads
Message-ID: <402c10cd0807132107s29c470f7hb834bd5c00ef399e@mail.gmail.com>
URL: https://gitlist.dev/e/402c10cd0807132107s29c470f7hb834bd5c00ef399e%40mail.gmail.com

```
Reduce_heads used by build in merge failed to find the correct
heads in cases where duplicate heads are specified.
---
This should fix the last breakage I found. ([PATCH/Test] Build in
merge is broken)
I have squashed in Miklos's fix and the two tests cases to protect this.

I have several other test cases that were used for the --ff-only patch
I worked on.
Many of the cases for that patch gives protection not currently in any of the
existing tests.  If there is interest for it I can squash them in as well.

 commit.c         |    8 +++++++-
 t/t7600-merge.sh |   22 ++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletions(-)

diff --git a/commit.c b/commit.c
index d20b14e..4cacf4c 100644
--- a/commit.c
+++ b/commit.c
@@ -746,8 +746,14 @@ struct commit_list *reduce_heads(struct commit_list *heads)
                struct commit_list *q, *base;

                num_other = 0;
+               for (q = heads; q != p; q = q->next) {
+                       if (p->item == q->item)
+                               break;
+               }
+               if (q != p)
+                       continue;
                for (q = heads; q; q = q->next) {
-                       if (p == q)
+                       if (p->item == q->item)
                                continue;
                        other[num_other++] = q->item;
                }
diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh
index 16f4608..80cfee6 100755
--- a/t/t7600-merge.sh
+++ b/t/t7600-merge.sh
@@ -465,4 +465,26 @@ test_expect_success 'merge log message' '

 test_debug 'gitk --all'

+test_expect_success 'merge c1 with c0, c2, c0, and c1' '
+       git reset --hard c1 &&
+       git config branch.master.mergeoptions "" &&
+       test_tick &&
+       git merge c0 c2 c0 c1 &&
+       verify_merge file result.1-5 &&
+       verify_parents $c1 $c2
+'
+
+test_debug 'gitk --all'
+
+test_expect_success 'merge c1 with c1 and c2' '
+       git reset --hard c1 &&
+       git config branch.master.mergeoptions "" &&
+       test_tick &&
+       git merge c1 c2 &&
+       verify_merge file result.1-5 &&
+       verify_parents $c1 $c2
+'
+
+test_debug 'gitk --all'
+
 test_done
-- 
Sverre Hvammen Johansen

```

## Johannes Schindelin, 2008-07-14 09:30

Subject: Re: [PATCH] Fix reduce_heads
Message-ID: <alpine.LSU.1.00.0807141128240.3486@wbgn129.biozentrum.uni-wuerzburg.de>
URL: https://gitlist.dev/e/alpine.LSU.1.00.0807141128240.3486%40wbgn129.biozentrum.uni-wuerzburg.de
In-Reply-To: <402c10cd0807132107s29c470f7hb834bd5c00ef399e@mail.gmail.com>

```
Hi,

On Sun, 13 Jul 2008, Sverre Hvammen Johansen wrote:

> Reduce_heads used by build in merge failed to find the correct
> heads in cases where duplicate heads are specified.

I liked Junio's explanation better.

> This should fix the last breakage I found. ([PATCH/Test] Build in
> merge is broken)
> I have squashed in Miklos's fix and the two tests cases to protect this.

I'd rather not have it squashed in.  Miklos is a GSoC student, and at the 
end I want to show the shortlog to tell Google how he fared.

Unfortunately, Miklos is on holiday this week, so he cannot send a mail of 
his own.  Junio, could you fake a commit message with a sign-off for 
Miklos, or do you want me to do it?

Ciao,
Dscho

```

## Miklos Vajna, 2008-07-14 11:44

Subject: Re: [PATCH] Fix reduce_heads
Message-ID: <20080714114453.GL10347@genesis.frugalware.org>
URL: https://gitlist.dev/e/20080714114453.GL10347%40genesis.frugalware.org
In-Reply-To: <alpine.LSU.1.00.0807141128240.3486@wbgn129.biozentrum.uni-wuerzburg.de>

```
On Mon, Jul 14, 2008 at 11:30:24AM +0200, Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
> Unfortunately, Miklos is on holiday this week, so he cannot send a mail of 
> his own.  Junio, could you fake a commit message with a sign-off for 
> Miklos, or do you want me to do it?

I'll go out tomorrow, so I can send that it today. Sorry for not sending
a proper patch for the first time. ;-)

```

## Miklos Vajna, 2008-07-14 11:57

Subject: Re: [PATCH] Fix reduce_heads
Message-ID: <20080714115725.GM10347@genesis.frugalware.org>
URL: https://gitlist.dev/e/20080714115725.GM10347%40genesis.frugalware.org
In-Reply-To: <20080714114453.GL10347@genesis.frugalware.org>

```
On Mon, Jul 14, 2008 at 01:44:53PM +0200, Miklos Vajna <vmiklos@frugalware.org> wrote:
> I'll go out tomorrow, so I can send that it today. Sorry for not sending
> a proper patch for the first time. ;-)

Ah, It's already in 'pu', so never mind.

```
