# [PATCH] rebase-i: keep old parents when preserving merges

7 messages from 2008-07-16 to 2008-07-16. Participants: Stephan Beyer, Johannes Schindelin, Junio C Hamano.
Thread: https://gitlist.dev/t/14476

## Stephan Beyer, 2008-07-16 01:51

Subject: [PATCH] rebase-i: keep old parents when preserving merges
Message-ID: <1216173109-11155-1-git-send-email-s-beyer@gmx.net>
URL: https://gitlist.dev/e/1216173109-11155-1-git-send-email-s-beyer%40gmx.net

```
This patch fixes two issues for rebase -i with preserving
merges of unrelated branches.

Merge parents that are part of an unrelated branch have not been
kept as a parent in some cases.
That means, a rewritten merge commit has either lost a parent
or rebase tried to cherry-pick this merge commit which resulted
in an error.

Signed-off-by: Stephan Beyer <s-beyer@gmx.net>
---
 git-rebase--interactive.sh |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index a35212d..0df7640 100755
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -174,6 +174,8 @@ pick_one_preserving_merges () {
 				new_parents="$new_parents $new_p"
 				;;
 			esac
+		else
+			new_parents="$new_parents $p"
 		fi
 	done
 	case $fast_forward in
-- 
1.5.6.3.357.ge6ecd

```

## Stephan Beyer, 2008-07-16 02:26

Subject: Re: [PATCH] rebase-i: keep old parents when preserving merges
Message-ID: <20080716022651.GA11611@leksak.fem-net>
URL: https://gitlist.dev/e/20080716022651.GA11611%40leksak.fem-net
In-Reply-To: <1216173109-11155-1-git-send-email-s-beyer@gmx.net>

```
I have to admit that the subject is pretty ambiguous.

Sorry :) I should go to bed.
  Stephan

-- 
Stephan Beyer <s-beyer@gmx.net>, PGP 0x6EDDD207FCC5040F

```

## Johannes Schindelin, 2008-07-16 02:33

Subject: Re: [PATCH] rebase-i: keep old parents when preserving merges
Message-ID: <alpine.DEB.1.00.0807160432480.2841@eeepc-johanness>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0807160432480.2841%40eeepc-johanness
In-Reply-To: <1216173109-11155-1-git-send-email-s-beyer@gmx.net>

```
Hi,

On Wed, 16 Jul 2008, Stephan Beyer wrote:

> This patch fixes two issues for rebase -i with preserving
> merges of unrelated branches.

Two?  What's the second?

Patch is obviously good.

Thanks,
Dscho

```

## Stephan Beyer, 2008-07-16 09:43

Subject: Re: [PATCH] rebase-i: keep old parents when preserving merges
Message-ID: <20080716094301.GA25087@leksak.fem-net>
URL: https://gitlist.dev/e/20080716094301.GA25087%40leksak.fem-net
In-Reply-To: <alpine.DEB.1.00.0807160432480.2841@eeepc-johanness>

```
Hi,

Johannes Schindelin wrote:
> Hi,
> 
> On Wed, 16 Jul 2008, Stephan Beyer wrote:
> 
> > This patch fixes two issues for rebase -i with preserving
> > merges of unrelated branches.
> 
> Two?  What's the second?

Oh, eh, well ;)
It's only one bug, but it results in two different behaviors...
If you have a merge with more than two parents and not all are lost,
then it merges with too few parents.
If you have a merge with exactly two parents and one is lost, then
it tries to cherry-pick (with an error).
"Two" "issues" :)

Regards.
  Stephan

-- 
Stephan Beyer <s-beyer@gmx.net>, PGP 0x6EDDD207FCC5040F

```

## Johannes Schindelin, 2008-07-16 10:24

Subject: Re: [PATCH] rebase-i: keep old parents when preserving merges
Message-ID: <alpine.DEB.1.00.0807161223210.8503@eeepc-johanness>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0807161223210.8503%40eeepc-johanness
In-Reply-To: <20080716094301.GA25087@leksak.fem-net>

```
Hi,

On Wed, 16 Jul 2008, Stephan Beyer wrote:

> Johannes Schindelin wrote:
> 
> > On Wed, 16 Jul 2008, Stephan Beyer wrote:
> > 
> > > This patch fixes two issues for rebase -i with preserving merges of 
> > > unrelated branches.
> > 
> > Two?  What's the second?
> 
> Oh, eh, well ;)
> It's only one bug, but it results in two different behaviors...

Ah, okay.  Worthwhile clarifying in the commit message.

Thanks for the patch,
Dscho

```

## Junio C Hamano, 2008-07-16 21:36

Subject: Re: [PATCH] rebase-i: keep old parents when preserving merges
Message-ID: <7vd4ldpl3k.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vd4ldpl3k.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <1216173109-11155-1-git-send-email-s-beyer@gmx.net>

```
Stephan Beyer <s-beyer@gmx.net> writes:

... Based on the discussion thread, here is a rewrite of the log message.

> When "rebase -i -p" tries to preserve merges of unrelated branches, it
> lost some parents:
>
>  - When you have more than two parents, the commit in the new history
>    ends up with fewer than expected number of parents and this breakage
>    goes unnoticed;
>
>  - When you are rebasing a merge with two parents and one is lost, the
>    command tries to cherry-pick the original merge commit, and the command
>    fails.
>
> Signed-off-by: Stephan Beyer <s-beyer@gmx.net>
>
> diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
> index a35212d..0df7640 100755
> --- a/git-rebase--interactive.sh
> +++ b/git-rebase--interactive.sh
> @@ -174,6 +174,8 @@ pick_one_preserving_merges () {
>  				new_parents="$new_parents $new_p"
>  				;;
>  			esac
> +		else
> +			new_parents="$new_parents $p"
>  		fi
>  	done

Reading the surrounding code, it makes me wonder if you also need to futz
with variables like $preserve and $fast_forward.

```

## Stephan Beyer, 2008-07-16 21:51

Subject: Re: [PATCH] rebase-i: keep old parents when preserving merges
Message-ID: <20080716215111.GB18558@leksak.fem-net>
URL: https://gitlist.dev/e/20080716215111.GB18558%40leksak.fem-net
In-Reply-To: <7vd4ldpl3k.fsf@gitster.siamese.dyndns.org>

```
Hi,

Junio C Hamano wrote:
> Stephan Beyer <s-beyer@gmx.net> writes:
> 
> ... Based on the discussion thread, here is a rewrite of the log message.
> 
> > When "rebase -i -p" tries to preserve merges of unrelated branches, it
> > lost some parents:
> >
> >  - When you have more than two parents, the commit in the new history
> >    ends up with fewer than expected number of parents and this breakage
> >    goes unnoticed;
> >
> >  - When you are rebasing a merge with two parents and one is lost, the
> >    command tries to cherry-pick the original merge commit, and the command
> >    fails.
> >
> > Signed-off-by: Stephan Beyer <s-beyer@gmx.net>

Ok, big thanks :)

> > diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
> > index a35212d..0df7640 100755
> > --- a/git-rebase--interactive.sh
> > +++ b/git-rebase--interactive.sh
> > @@ -174,6 +174,8 @@ pick_one_preserving_merges () {
> >  				new_parents="$new_parents $new_p"
> >  				;;
> >  			esac
> > +		else
> > +			new_parents="$new_parents $p"
> >  		fi
> >  	done
> 
> Reading the surrounding code, it makes me wonder if you also need to futz
> with variables like $preserve and $fast_forward.

No, I would not see a reason for that.

Regards,
  Stephan

-- 
Stephan Beyer <s-beyer@gmx.net>, PGP 0x6EDDD207FCC5040F

```
