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

[PATCH RFC] builtin/log: include From in git show --format=email

From
AGAntonin Godard <antonin.godard@bootlin.com>
Date
Feb 14, 2025, 16:31 UTC
Message-ID
<20250214-git-show-from-email-v1-1-df6469635454@bootlin.com>

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: Junio C Hamano
Message 1 of 4 in “builtin/log: include From in git show --format=email”
  1. builtin/log: include From in git show --format=emailAntonin Godard, Feb 14, 2025
  2. Junio C HamanoFeb 14, 2025
  3. Antonin GodardFeb 17, 2025
  4. Junio C HamanoFeb 18, 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.