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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxx>
---
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@xxxxxxxxxxx>





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux