git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 3/8] rebase --merge: fix reflog when continuing

From
PGPhillip Wood via GitGitGadget <gitgitgadget@gmail.com>
Date
Oct 12, 2022, 09:35 UTC
Message-ID
<ea4da25a19cca80f04fb6b88d46937056406c5b7.1665567312.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1150.v3.git.1665567312.gitgitgadget@gmail.com>
From: Phillip Wood <phillip.wood@dunelm.org.uk>

The reflog message for a conflict resolution committed by "rebase --continue" looks like

	rebase (continue): commit subject line
Unfortunately the reflog message each subsequent pick look like
	rebase (continue) (pick): commit subject line

Fix this by setting the reflog message for "rebase --continue" in sequencer_continue() so it does not affect subsequent commits. This introduces a memory leak similar to the one leaking GIT_REFLOG_ACTION in pick_commits(). Both of these will be fixed in a future series that stops the sequencer calling setenv().

If we fail to commit the staged changes then we error out so GIT_REFLOG_ACTION does not need to be reset in that case.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 builtin/rebase.c          | 2 --
 sequencer.c               | 5 +++++
 t/t3406-rebase-message.sh | 9 +++++++--
 3 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/builtin/rebase.c b/builtin/rebase.c
index 51accb4fd61..488e6bdfd3e 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -1271,8 +1271,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 		int fd;
 
 		options.action = "continue";
-		set_reflog_action(&options);
-
 		/* Sanity check */
 		if (get_oid("HEAD", &head))
 			die(_("Cannot read HEAD"));
diff --git a/sequencer.c b/sequencer.c
index 61a8e0020d5..5790b35d763 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -4785,6 +4785,8 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
 	if (read_populate_opts(opts))
 		return -1;
 	if (is_rebase_i(opts)) {
+		char *previous_reflog_action;
+
 		if ((res = read_populate_todo(r, &todo_list, opts)))
 			goto release_todo_list;
 
@@ -4795,10 +4797,13 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts)
 			unlink(rebase_path_dropped());
 		}
 
+		previous_reflog_action = xstrdup(getenv(GIT_REFLOG_ACTION));
+		setenv(GIT_REFLOG_ACTION, reflog_message(opts, "continue", NULL), 1);
 		if (commit_staged_changes(r, opts, &todo_list)) {
 			res = -1;
 			goto release_todo_list;
 		}
+		setenv(GIT_REFLOG_ACTION, previous_reflog_action, 1);
 	} else if (!file_exists(get_todo_path(opts)))
 		return continue_single_pick(r, opts);
 	else if ((res = read_populate_todo(r, &todo_list, opts)))
diff --git a/t/t3406-rebase-message.sh b/t/t3406-rebase-message.sh
index 5253dd1551d..3ca2fbb0d59 100755
--- a/t/t3406-rebase-message.sh
+++ b/t/t3406-rebase-message.sh
@@ -17,6 +17,7 @@ test_expect_success 'setup' '
 
 	git checkout -b conflicts O &&
 	test_commit P &&
+	test_commit conflict-X fileX &&
 	test_commit Q &&
 
 	git checkout -b topic O &&
@@ -107,13 +108,17 @@ test_reflog () {
 			GIT_REFLOG_ACTION="$reflog_action" &&
 			export GIT_REFLOG_ACTION
 		fi &&
-		git rebase $mode main
+		test_must_fail git rebase $mode main &&
+		echo resolved >fileX &&
+		git add fileX &&
+		git rebase --continue
 	) &&
 
-	git log -g --format=%gs -4 >actual &&
+	git log -g --format=%gs -5 >actual &&
 	write_reflog_expect <<-EOF &&
 	${reflog_action:-rebase} (finish): returning to refs/heads/conflicts
 	${reflog_action:-rebase} (pick): Q
+	${reflog_action:-rebase} (continue): conflict-X
 	${reflog_action:-rebase} (pick): P
 	${reflog_action:-rebase} (start): checkout main
 	EOF
-- 
gitgitgadget
Previous: Phillip Wood via GitGitGadgetNext: Phillip Wood via GitGitGadget
Message 47 of 73 in “rebase: make reflog messages independent of the backend”
  1. 0/7 rebase: make reflog messages independent of the backendPhillip Wood via GitGitGadget, Feb 21, 2022
  2. 3/7 rebase --merge: fix reflog message after skippingPhillip Wood via GitGitGadget, Feb 21, 2022
  3. Elijah NewrenApr 17, 2022
  4. 4/7 rebase --apply: respect GIT_REFLOG_ACTIONPhillip Wood via GitGitGadget, Feb 21, 2022
  5. Christian CouderApr 7, 2022
  6. Phillip WoodApr 15, 2022
  7. 7/7 rebase: cleanup action handlingPhillip Wood via GitGitGadget, Feb 21, 2022
  8. Elijah NewrenApr 17, 2022
  9. 5/7 rebase --apply: make reflog messages match rebase --mergePhillip Wood via GitGitGadget, Feb 21, 2022
  10. Elijah NewrenApr 17, 2022
  11. 2/7 rebase --merge: fix reflog when continuingPhillip Wood via GitGitGadget, Feb 21, 2022
  12. Christian CouderApr 7, 2022
  13. Phillip WoodApr 15, 2022
  14. Elijah NewrenApr 17, 2022
  15. 1/7 rebase --apply: remove duplicated codePhillip Wood via GitGitGadget, Feb 21, 2022
  16. Christian CouderApr 7, 2022
  17. Elijah NewrenApr 17, 2022
  18. 6/7 rebase --abort: improve reflog messagePhillip Wood via GitGitGadget, Feb 21, 2022
  19. Elijah NewrenApr 17, 2022
  20. Review Request (was Re: [PATCH 0/7] rebase: make reflog messages independent of the backend)Phillip Wood, Apr 4, 2022
  21. Elijah NewrenApr 17, 2022
  22. Phillip WoodApr 18, 2022
  23. Christian CouderApr 7, 2022
  24. Elijah NewrenApr 17, 2022
  25. 0/8 rebase: make reflog messages independent of the backendPhillip Wood via GitGitGadget, Apr 20, 2022
  26. 2/8 t3406: rework rebase reflog testsPhillip Wood via GitGitGadget, Apr 20, 2022
  27. Junio C HamanoApr 20, 2022
  28. 1/8 rebase --apply: remove duplicated codePhillip Wood via GitGitGadget, Apr 20, 2022
  29. Ævar Arnfjörð BjarmasonApr 20, 2022
  30. Junio C HamanoApr 20, 2022
  31. Junio C HamanoApr 20, 2022
  32. 3/8 rebase --merge: fix reflog when continuingPhillip Wood via GitGitGadget, Apr 20, 2022
  33. 4/8 rebase --merge: fix reflog message after skippingPhillip Wood via GitGitGadget, Apr 20, 2022
  34. 5/8 rebase --apply: respect GIT_REFLOG_ACTIONPhillip Wood via GitGitGadget, Apr 20, 2022
  35. 6/8 rebase --apply: make reflog messages match rebase --mergePhillip Wood via GitGitGadget, Apr 20, 2022
  36. Ævar Arnfjörð BjarmasonApr 20, 2022
  37. Junio C HamanoApr 20, 2022
  38. 7/8 rebase --abort: improve reflog messagePhillip Wood via GitGitGadget, Apr 20, 2022
  39. 8/8 rebase: cleanup action handlingPhillip Wood via GitGitGadget, Apr 20, 2022
  40. Ævar Arnfjörð BjarmasonApr 20, 2022
  41. 0/8 rebase: make reflog messages independent of the backendPhillip Wood via GitGitGadget, Oct 12, 2022
  42. 1/8 rebase --apply: remove duplicated codePhillip Wood via GitGitGadget, Oct 12, 2022
  43. Junio C HamanoOct 12, 2022
  44. Junio C HamanoOct 13, 2022
  45. Phillip WoodOct 20, 2022
  46. 2/8 t3406: rework rebase reflog testsPhillip Wood via GitGitGadget, Oct 12, 2022
  47. 3/8 rebase --merge: fix reflog when continuingPhillip Wood via GitGitGadget, Oct 12, 2022
  48. 4/8 rebase --merge: fix reflog message after skippingPhillip Wood via GitGitGadget, Oct 12, 2022
  49. 5/8 rebase --apply: respect GIT_REFLOG_ACTIONPhillip Wood via GitGitGadget, Oct 12, 2022
  50. 6/8 rebase --apply: make reflog messages match rebase --mergePhillip Wood via GitGitGadget, Oct 12, 2022
  51. 7/8 rebase --abort: improve reflog messagePhillip Wood via GitGitGadget, Oct 12, 2022
  52. 8/8 rebase: cleanup action handlingPhillip Wood via GitGitGadget, Oct 12, 2022
  53. Junio C HamanoOct 12, 2022
  54. Phillip WoodOct 13, 2022
  55. Junio C HamanoOct 13, 2022
  56. 0/8 rebase: make reflog messages independent of the backendPhillip Wood via GitGitGadget, Oct 21, 2022
  57. 1/8 t3406: rework rebase reflog testsPhillip Wood via GitGitGadget, Oct 21, 2022
  58. 2/8 rebase --apply: improve fast-forward reflog messagePhillip Wood via GitGitGadget, Oct 21, 2022
  59. 3/8 rebase --merge: fix reflog when continuingPhillip Wood via GitGitGadget, Oct 21, 2022
  60. Junio C HamanoOct 21, 2022
  61. Phillip WoodOct 25, 2022
  62. Junio C HamanoOct 25, 2022
  63. Phillip WoodOct 26, 2022
  64. Junio C HamanoOct 26, 2022
  65. 4/8 rebase --merge: fix reflog message after skippingPhillip Wood via GitGitGadget, Oct 21, 2022
  66. 5/8 rebase --apply: respect GIT_REFLOG_ACTIONPhillip Wood via GitGitGadget, Oct 21, 2022
  67. Junio C HamanoOct 21, 2022
  68. 6/8 rebase --apply: make reflog messages match rebase --mergePhillip Wood via GitGitGadget, Oct 21, 2022
  69. Junio C HamanoOct 21, 2022
  70. 7/8 rebase --abort: improve reflog messagePhillip Wood via GitGitGadget, Oct 21, 2022
  71. Junio C HamanoOct 21, 2022
  72. 8/8 rebase: cleanup action handlingPhillip Wood via GitGitGadget, Oct 21, 2022
  73. Junio C HamanoOct 21, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.