git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RFC] builtin/log: include From in git show --format=email
@ 2025-02-14 16:31 Antonin Godard
  2025-02-14 20:35 ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Antonin Godard @ 2025-02-14 16:31 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Emma Brooks, Patrick Steinhardt,
	Ævar Arnfjörð Bjarmason, Daniel Li, Antonin Godard

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>


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-02-18 21:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-14 16:31 [PATCH RFC] builtin/log: include From in git show --format=email Antonin Godard
2025-02-14 20:35 ` Junio C Hamano
2025-02-17 12:42   ` Antonin Godard
2025-02-18 21:45     ` Junio C Hamano

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).