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

[PATCH v3 6/8] rebase --apply: make reflog messages match rebase --merge

From
PGPhillip Wood via GitGitGadget <gitgitgadget@gmail.com>
Date
Oct 12, 2022, 09:35 UTC
Message-ID
<a5338e6bdd8cc783f01653cf4b668273bc2abec2.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 apply backend creates slightly different reflog messages to the merge backend when starting or finishing a rebase and when picking commits. These differences make it harder than it needs to be to parse the reflog (I have a script that reads the finishing messages from rebase and it is a pain to have to accommodate two different message formats). While it is possible to determine the backend used for a rebase from the reflog messages, the differences are not designed for that purpose. c2417d3af7 (rebase: drop '-i' from the reflog for interactive-based rebases, 2020-02-15) removed the clear distinction between the reflog messages of the two backends without complaint.

As the merge backend is the default it is likely to be the format most common in existing reflogs. For that reason the apply backend is changed to format its reflog messages to match the merge backend as closely as possible. Note that there is still a difference as when committing a conflict resolution the apply backend will use "(pick)" rather than "(continue)" because it is not currently possible to change the message for a single commit.

In addition to c2417d3af7 we also changed the reflog messages in 68aa495b59 (rebase: implement --merge via the interactive machinery, 2018-12-11) and 2ac0d6273f (rebase: change the default backend from "am" to "merge", 2020-02-15). This commit makes the same change to "git rebase --apply" that 2ac0d6273f made to "git rebase" without any backend specific options. As the messages are changed to use an existing format any scripts that can parse the reflog messages of the default rebase backend should be unaffected by this change.

There are existing tests for the messages from both backends which are adjusted to ensure that they do not get out of sync in the future.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 builtin/rebase.c          | 9 +++++----
 t/t3406-rebase-message.sh | 2 +-
 2 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/builtin/rebase.c b/builtin/rebase.c
index f7b00efeb92..ed612c2d0c3 100644
--- a/builtin/rebase.c
+++ b/builtin/rebase.c
@@ -582,10 +582,10 @@ static int move_to_original_branch(struct rebase_options *opts)
 	if (!opts->onto)
 		BUG("move_to_original_branch without onto");
 
-	strbuf_addf(&branch_reflog, "%s finished: %s onto %s",
+	strbuf_addf(&branch_reflog, "%s (finish): %s onto %s",
 		    getenv(GIT_REFLOG_ACTION_ENVIRONMENT),
 		    opts->head_name, oid_to_hex(&opts->onto->object.oid));
-	strbuf_addf(&head_reflog, "%s finished: returning to %s",
+	strbuf_addf(&head_reflog, "%s (finish): returning to %s",
 		    getenv(GIT_REFLOG_ACTION_ENVIRONMENT), opts->head_name);
 	ropts.branch = opts->head_name;
 	ropts.flags = RESET_HEAD_REFS_ONLY;
@@ -615,7 +615,8 @@ static int run_am(struct rebase_options *opts)
 
 	am.git_cmd = 1;
 	strvec_push(&am.args, "am");
-
+	strvec_pushf(&am.env, GIT_REFLOG_ACTION_ENVIRONMENT "=%s (pick)",
+		     getenv(GIT_REFLOG_ACTION_ENVIRONMENT));
 	if (opts->action && !strcmp("continue", opts->action)) {
 		strvec_push(&am.args, "--resolved");
 		strvec_pushf(&am.args, "--resolvemsg=%s", resolvemsg);
@@ -1789,7 +1790,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
 		printf(_("First, rewinding head to replay your work on top of "
 			 "it...\n"));
 
-	strbuf_addf(&msg, "%s: checkout %s",
+	strbuf_addf(&msg, "%s (start): checkout %s",
 		    getenv(GIT_REFLOG_ACTION_ENVIRONMENT), options.onto_name);
 	ropts.oid = &options.onto->object.oid;
 	ropts.orig_head = &options.orig_head->object.oid,
diff --git a/t/t3406-rebase-message.sh b/t/t3406-rebase-message.sh
index bb2a4949abc..5c6cd9af3bc 100755
--- a/t/t3406-rebase-message.sh
+++ b/t/t3406-rebase-message.sh
@@ -88,7 +88,7 @@ test_expect_success 'error out early upon -C<n> or --whitespace=<bad>' '
 write_reflog_expect () {
 	if test $mode = --apply
 	then
-		sed 's/(finish)/finished/; s/ ([^)]*)//'
+		sed 's/(continue)/(pick)/'
 	else
 		cat
 	fi >expect
-- 
gitgitgadget
Previous: Phillip Wood via GitGitGadgetNext: Phillip Wood via GitGitGadget
Message 50 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.