From: Antonin Godard <antonin.godard@bootlin.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Emma Brooks" <me@pluvano.com>, "Patrick Steinhardt" <ps@pks.im>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"Daniel Li" <dan@danielyli.com>,
"Antonin Godard" <antonin.godard@bootlin.com>
Subject: [PATCH RFC] builtin/log: include From in git show --format=email
Date: Fri, 14 Feb 2025 17:31:13 +0100 [thread overview]
Message-ID: <20250214-git-show-from-email-v1-1-df6469635454@bootlin.com> (raw)
Currently, when the format.from and format.forceInBodyFrom options are
configured, the command `git show --format=email <commit>` command does
not include "From: user <email>" in the body, even though I believe it
is expected when using this format.
While the code exists in log-tree.c to take the identity into account:
if (opt->from_ident.mail_begin && opt->from_ident.name_begin)
ctx.from_ident = &opt->from_ident;
the mail_begin and name_begin would always be null pointers
because opt->from_ident is never filled in with the identity from
cmd_show.
This commit adds the `from` member to struct log_config, and reads the
user configuration to fill in rev.from_ident. It also reuses
the existing force_in_body_from variable to take this option into
account.
Signed-off-by: Antonin Godard <antonin.godard@bootlin.com>
---
This is probably not the best solution, as we already have the from
member in struct format_config, so adding it in struct log_config is a bit
redundant. However, this is an RFC that hopefully will get my question
answered: is my belief to have the From field shown with this command
correct?
---
builtin/log.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/builtin/log.c b/builtin/log.c
index e41f88945e..16a4889c01 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -113,6 +113,7 @@ struct log_config {
int fmt_patch_name_max;
char *fmt_pretty;
char *default_date_mode;
+ char *from;
};
static void log_config_init(struct log_config *cfg)
@@ -592,6 +593,19 @@ static int git_log_config(const char *var, const char *value,
cfg->default_encode_email_headers = git_config_bool(var, value);
return 0;
}
+ if (!strcmp(var, "format.from")) {
+ int b = git_parse_maybe_bool(value);
+ FREE_AND_NULL(cfg->from);
+ if (b < 0)
+ cfg->from = xstrdup(value);
+ else if (b)
+ cfg->from = xstrdup(git_committer_info(IDENT_NO_DATE));
+ return 0;
+ }
+ if (!strcmp(var, "format.forceinbodyfrom")) {
+ force_in_body_from = git_config_bool(var, value);
+ return 0;
+ }
if (!strcmp(var, "log.abbrevcommit")) {
cfg->default_abbrev_commit = git_config_bool(var, value);
return 0;
@@ -799,6 +813,13 @@ int cmd_show(int argc,
return ret;
}
+ if (cfg.from) {
+ if (split_ident_line(&rev.from_ident, cfg.from, strlen(cfg.from)))
+ die(_("invalid ident line: %s"), cfg.from);
+ }
+
+ rev.force_in_body_from = force_in_body_from;
+
rev.diffopt.no_free = 1;
for (i = 0; i < rev.pending.nr && !ret; i++) {
struct object *o = rev.pending.objects[i].item;
---
base-commit: 9520f7d9985d8879bddd157309928fc0679c8e92
change-id: 20250117-git-show-from-email-62f0e4004d7d
Best regards,
--
Antonin Godard <antonin.godard@bootlin.com>
next reply other threads:[~2025-02-14 16:32 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-14 16:31 Antonin Godard [this message]
2025-02-14 20:35 ` [PATCH RFC] builtin/log: include From in git show --format=email Junio C Hamano
2025-02-17 12:42 ` Antonin Godard
2025-02-18 21:45 ` 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=20250214-git-show-from-email-v1-1-df6469635454@bootlin.com \
--to=antonin.godard@bootlin.com \
--cc=avarab@gmail.com \
--cc=dan@danielyli.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=me@pluvano.com \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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;
as well as URLs for NNTP newsgroup(s).