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

[PATCH 4/5] pretty: Add name_and_address_only parameter

From
ZWZev Weiss <zev@bewilderbeest.net>
Date
Jan 19, 2023, 22:38 UTC
Message-ID
<20230119223858.29262-5-zev@bewilderbeest.net>
In-Reply-To
<20230119223858.29262-1-zev@bewilderbeest.net>

This is meant to be used with pp_user_info() when using it to format email recipients generated by --to-cmd/--cc-cmd. When set it omits the leading 'From: ', trailing linefeed, and the date suffix, and additionally will return the input string unmodified if split_ident_line() can't parse it (e.g. for a bare email address).

Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
---
 pretty.c | 15 ++++++++++++---
 pretty.h |  1 +
 2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/pretty.c b/pretty.c
index 1e1e21878c83..e6798fadc107 100644
--- a/pretty.c
+++ b/pretty.c
@@ -509,8 +509,11 @@ void pp_user_info(struct pretty_print_context *pp,
 		return;
 
 	line_end = strchrnul(line, '\n');
-	if (split_ident_line(&ident, line, line_end - line))
+	if (split_ident_line(&ident, line, line_end - line)) {
+		if (pp->name_and_address_only)
+			strbuf_addstr(sb, line);
 		return;
+	}
 
 	mailbuf = ident.mail_begin;
 	maillen = ident.mail_end - ident.mail_begin;
@@ -538,7 +541,8 @@ void pp_user_info(struct pretty_print_context *pp,
 			namelen = pp->from_ident->name_end - namebuf;
 		}
 
-		strbuf_addstr(sb, "From: ");
+		if (!pp->name_and_address_only)
+			strbuf_addstr(sb, "From: ");
 		if (pp->encode_email_headers &&
 		    needs_rfc2047_encoding(namebuf, namelen)) {
 			add_rfc2047(sb, namebuf, namelen,
@@ -558,7 +562,9 @@ void pp_user_info(struct pretty_print_context *pp,
 		if (max_length <
 		    last_line_length(sb) + strlen(" <") + maillen + strlen(">"))
 			strbuf_addch(sb, '\n');
-		strbuf_addf(sb, " <%.*s>\n", (int)maillen, mailbuf);
+		strbuf_addf(sb, " <%.*s>", (int)maillen, mailbuf);
+		if (!pp->name_and_address_only)
+			strbuf_addch(sb, '\n');
 	} else {
 		struct strbuf id = STRBUF_INIT;
 		enum grep_header_field field = GREP_HEADER_FIELD_MAX;
@@ -582,6 +588,9 @@ void pp_user_info(struct pretty_print_context *pp,
 		strbuf_release(&id);
 	}
 
+	if (pp->name_and_address_only)
+		return;
+
 	switch (pp->fmt) {
 	case CMIT_FMT_MEDIUM:
 		strbuf_addf(sb, "Date:   %s\n",
diff --git a/pretty.h b/pretty.h
index f34e24c53a49..306666e99294 100644
--- a/pretty.h
+++ b/pretty.h
@@ -39,6 +39,7 @@ struct pretty_print_context {
 	int preserve_subject;
 	struct date_mode date_mode;
 	unsigned date_mode_explicit:1;
+	unsigned name_and_address_only:1;
 	int print_email_subject;
 	int expand_tabs_in_log;
 	int need_8bit_cte;
-- 
2.39.1.236.ga8a28b9eace8
Previous: Junio C HamanoNext: Junio C Hamano
Message 7 of 14 in “format-patch: Add --{to,cc}-cmd support”
  1. 0/5 format-patch: Add --{to,cc}-cmd supportZev Weiss, Jan 19, 2023
  2. 3/5 log: Push to/cc handling down into show_log()Zev Weiss, Jan 19, 2023
  3. Junio C HamanoJan 20, 2023
  4. Calvin WanFeb 1, 2023
  5. 2/5 log: Refactor duplicated code to headerize recipient listsZev Weiss, Jan 19, 2023
  6. Junio C HamanoJan 25, 2023
  7. 4/5 pretty: Add name_and_address_only parameterZev Weiss, Jan 19, 2023
  8. Junio C HamanoJan 25, 2023
  9. Calvin WanFeb 1, 2023
  10. 1/5 t4014: Add test checking cover-letter To headerZev Weiss, Jan 19, 2023
  11. Calvin WanFeb 1, 2023
  12. 5/5 format-patch: Add support for --{to,cc}-cmd flagsZev Weiss, Jan 19, 2023
  13. Calvin WanFeb 1, 2023
  14. Calvin WanFeb 1, 2023

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.