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

[PATCH 2/3] builtin/am.c: add a message-id commit header

From
James Bottomley <james.bottomley@hansenpartnership.com>
Date
Oct 16, 2025, 18:57 UTC
Message-ID
<20251016185758.21996-3-James.Bottomley@HansenPartnership.com>
In-Reply-To
<20251016185758.21996-1-James.Bottomley@HansenPartnership.com>

Now that mailinfo is updated to collect the message_id all the time, use this in do_commit to add a "message-id" extra header containing the message_id if it exists. This means that git am will always record the message-id if it can be found in the commit. It will still add it to the trailer if -m is specified, keeping the behaviour backwards compatible.

Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
---
 builtin/am.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/builtin/am.c b/builtin/am.c
index 277c2e7937..ab05701a8d 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -119,6 +119,7 @@ struct am_state {
 	char *author_name;
 	char *author_email;
 	char *author_date;
+	char *msg_id;
 	char *msg;
 	size_t msg_len;
 
@@ -187,6 +188,7 @@ static void am_state_release(struct am_state *state)
 	free(state->author_email);
 	free(state->author_date);
 	free(state->msg);
+	free(state->msg_id);
 	strvec_clear(&state->git_apply_opts);
 }
 
@@ -1313,6 +1315,9 @@ static int parse_mail(struct am_state *state, const char *mail)
 	assert(!state->msg);
 	state->msg = strbuf_detach(&msg, &state->msg_len);
 
+	assert(!state->msg_id);
+	state->msg_id = xstrdup_or_null(mi.message_id);
+
 finish:
 	strbuf_release(&msg);
 	strbuf_release(&author_date);
@@ -1668,6 +1673,7 @@ static void do_commit(const struct am_state *state)
 	struct commit_list *parents = NULL;
 	const char *reflog_msg, *author, *committer = NULL;
 	struct strbuf sb = STRBUF_INIT;
+	struct commit_extra_header *extra = NULL;
 
 	if (!state->no_verify && run_hooks(the_repository, "pre-applypatch"))
 		exit(1);
@@ -1699,9 +1705,16 @@ static void do_commit(const struct am_state *state)
 							 : state->author_date,
 				      IDENT_STRICT);
 
+	if (state->msg_id) {
+		CALLOC_ARRAY(extra, 1);
+		extra->key = xstrdup("message-id");
+		extra->value = xstrdup(state->msg_id);
+		extra->len = strlen(extra->value);
+	}
+
 	if (commit_tree_extended(state->msg, state->msg_len, &tree, parents,
 				 &commit, author, committer, state->sign_commit,
-				 NULL))
+				 extra))
 		die(_("failed to write commit object"));
 
 	reflog_msg = getenv("GIT_REFLOG_ACTION");
-- 
2.51.0
Previous: James BottomleyNext: brian m. carlson
Message 3 of 14 in “add a message-id header to git”
  1. 0/3 add a message-id header to gitJames Bottomley, Oct 16, 2025
  2. 1/3 mailinfo.c: always collect the message-idJames Bottomley, Oct 16, 2025
  3. 2/3 builtin/am.c: add a message-id commit headerJames Bottomley, Oct 16, 2025
  4. brian m. carlsonOct 16, 2025
  5. 3/3 t4150-am: add a test for message-id header collectionJames Bottomley, Oct 16, 2025
  6. Kristoffer HaugsbakkOct 16, 2025
  7. James BottomleyOct 16, 2025
  8. Kristoffer HaugsbakkOct 16, 2025
  9. Junio C HamanoOct 16, 2025
  10. James BottomleyOct 16, 2025
  11. Junio C HamanoOct 16, 2025
  12. Kristoffer HaugsbakkOct 16, 2025
  13. Kristoffer HaugsbakkOct 16, 2025
  14. Junio C HamanoOct 16, 2025

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.