Git Mailing List Archive mirror
 help / color / mirror / Atom feed
* notes handling broken on rebase
@ 2023-05-30  9:21 Uwe Kleine-König
  2023-05-31 13:29 ` Phillip Wood
  0 siblings, 1 reply; 2+ messages in thread
From: Uwe Kleine-König @ 2023-05-30  9:21 UTC (permalink / raw)
  To: git; +Cc: entwicklung

[-- Attachment #1: Type: text/plain, Size: 3433 bytes --]

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:

 - 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

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: notes handling broken on rebase
  2023-05-30  9:21 notes handling broken on rebase Uwe Kleine-König
@ 2023-05-31 13:29 ` Phillip Wood
  0 siblings, 0 replies; 2+ messages in thread
From: Phillip Wood @ 2023-05-31 13:29 UTC (permalink / raw)
  To: Uwe Kleine-König, git; +Cc: entwicklung

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
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-05-31 13:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-30  9:21 notes handling broken on rebase Uwe Kleine-König
2023-05-31 13:29 ` Phillip Wood

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).