Git Mailing List Archive mirror
 help / color / mirror / Atom feed
From: Phillip Wood <phillip.wood123@gmail.com>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>, git@vger.kernel.org
Cc: entwicklung@pengutronix.de
Subject: Re: notes handling broken on rebase
Date: Wed, 31 May 2023 14:29:46 +0100	[thread overview]
Message-ID: <c180ce59-459b-ee99-e4c0-c2fa6c765d77@gmail.com> (raw)
In-Reply-To: <20230530092155.3zbb5uxa7eisdzxb@pengutronix.de>

Hi Uwe

On 30/05/2023 10:21, Uwe Kleine-König wrote:
> Hello,
> 
> I found a bug in git rebase and how notes are retained using
> 
> 	uwe@taurus:~/tmp/gittest$ git version
> 	git version 2.41.0.rc2.161.g9c6817b8e7dd
> 
> , it also happens with 2.39.2.
> 
> Here comes a reproducer:

Thanks for reporting this and taking the time to provide an easy 
reproducer. I think the problem is that when git drops the commit in 
do_pick_commit() it still gets recorded as rewritten and so the notes 
are copied. To fix it we need to improve do_pick_commit() to return a 
value indicating that the commit was dropped so that we don't call 
record_in_rewritten() in pick_commits().

Best Wishes

Phillip


>   - Create some initial git history, just three commits A, B and C:
> 
> 	uwe@taurus:~/tmp/gittest$ git init
> 	Initialized empty Git repository in /home/uwe/tmp/gittest/.git/
> 
> 	uwe@taurus:~/tmp/gittest$ for i in A B C; do echo content $i >> file ; git add file ; git commit -m "$i" ; git notes add -m "notes for $i" ; git tag $i ; done
> 	[main (root-commit) db2548de5a3c] A
> 	 1 file changed, 1 insertion(+)
> 	 create mode 100644 file
> 	[main 2b8fa82afb3c] B
> 	 1 file changed, 1 insertion(+)
> 	[main 3dd5e4a2037e] C
> 	 1 file changed, 1 insertion(+)
> 
>   - Pick C on top of A:
> 
> 	uwe@taurus:~/tmp/gittest$ git checkout A
> 	HEAD is now at db2548de5a3c A
> 	uwe@taurus:~/tmp/gittest$ git cherry-pick C
> 	Auto-merging file
> 	CONFLICT (content): Merge conflict in file
> 	error: could not apply 3dd5e4a2037e... C
> 	hint: After resolving the conflicts, mark them with
> 	hint: "git add/rm <pathspec>", then run
> 	hint: "git cherry-pick --continue".
> 	hint: You can instead skip this commit with "git cherry-pick --skip".
> 	hint: To abort and get back to the state before "git cherry-pick",
> 	hint: run "git cherry-pick --abort".
> 	Recorded preimage for 'file'
> 	uwe@taurus:~/tmp/gittest$ { echo content A; echo content C; } > file
> 	uwe@taurus:~/tmp/gittest$ git add file
> 	uwe@taurus:~/tmp/gittest$ git cherry-pick --continue
> 	Recorded resolution for 'file'.
> 	[detached HEAD 6cfc9b7bd437] C
> 	 Date: Tue May 30 11:02:13 2023 +0200
> 	 1 file changed, 1 insertion(+)
> 
>   - Rebase {B, C} on top of A + C' (which results in skipping C):
> 
> 	uwe@taurus:~/tmp/gittest$ git rebase HEAD C
> 	Auto-merging file
> 	CONFLICT (content): Merge conflict in file
> 	error: could not apply 2b8fa82afb3c... B
> 	hint: Resolve all conflicts manually, mark them as resolved with
> 	hint: "git add/rm <conflicted_files>", then run "git rebase --continue".
> 	hint: You can instead skip this commit: run "git rebase --skip".
> 	hint: To abort and get back to the state before "git rebase", run "git rebase --abort".
> 	Recorded preimage for 'file'
> 	Could not apply 2b8fa82afb3c... B
> 	uwe@taurus:~/tmp/gittest$ { echo content A; echo content B; echo content C; } > file
> 	uwe@taurus:~/tmp/gittest$ git add file
> 	uwe@taurus:~/tmp/gittest$ git rebase --continue
> 	Recorded resolution for 'file'.
> 	[detached HEAD e5b3e28216f2] B
> 	 1 file changed, 1 insertion(+)
> 	dropping 3dd5e4a2037ecd31f5470561638cb065434eabbc C -- patch contents already upstream
> 	Successfully rebased and updated detached HEAD.
> 
> Now I have:
> 
> 	uwe@taurus:~/tmp/gittest$ git log --pretty=oneline --abbrev-commit --notes
> 	e5b3e28216f2 (HEAD) B
> 	Notes:
> 	    notes for B
> 	
> 	    notes for C
> 
> 	6cfc9b7bd437 C
> 	db2548de5a3c (tag: A) A
> 	Notes:
> 	    notes for A
> 
> The surprising part here is that (the new) B also has C's note. I would
> have expected that it only has its own one. I quickly looked into the
> source code, but didn't find an easy fix because the code that notices
> that C should be dropped (in do_pick_commit()) isn't where the note is
> copied (which I didn't find).
> 
> Best regards
> Uwe
> 


      reply	other threads:[~2023-05-31 13:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-30  9:21 notes handling broken on rebase Uwe Kleine-König
2023-05-31 13:29 ` Phillip Wood [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c180ce59-459b-ee99-e4c0-c2fa6c765d77@gmail.com \
    --to=phillip.wood123@gmail.com \
    --cc=entwicklung@pengutronix.de \
    --cc=git@vger.kernel.org \
    --cc=phillip.wood@dunelm.org.uk \
    --cc=u.kleine-koenig@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).