From: James Bottomley <James.Bottomley@HansenPartnership•com>
To: git@vger•kernel.org
Subject: [PATCH 2/3] builtin/am.c: add a message-id commit header
Date: Thu, 16 Oct 2025 14:57:57 -0400 [thread overview]
Message-ID: <20251016185758.21996-3-James.Bottomley@HansenPartnership.com> (raw)
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
next prev parent reply other threads:[~2025-10-16 18:59 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-16 18:57 [PATCH 0/3] add a message-id header to git James Bottomley
2025-10-16 18:57 ` [PATCH 1/3] mailinfo.c: always collect the message-id James Bottomley
2025-10-16 18:57 ` James Bottomley [this message]
2025-10-16 22:41 ` [PATCH 2/3] builtin/am.c: add a message-id commit header brian m. carlson
2025-10-16 18:57 ` [PATCH 3/3] t4150-am: add a test for message-id header collection James Bottomley
2025-10-16 19:26 ` [PATCH 0/3] add a message-id header to git Kristoffer Haugsbakk
2025-10-16 20:10 ` James Bottomley
2025-10-16 20:31 ` Kristoffer Haugsbakk
2025-10-16 20:32 ` Junio C Hamano
2025-10-16 21:00 ` James Bottomley
2025-10-16 21:18 ` Junio C Hamano
2025-10-16 21:28 ` Kristoffer Haugsbakk
2025-10-16 21:50 ` Kristoffer Haugsbakk
2025-10-16 22:15 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251016185758.21996-3-James.Bottomley@HansenPartnership.com \
--to=james.bottomley@hansenpartnership$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox