Re: notes handling broken on rebase

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux