From patchwork Thu Jan 19 22:38:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zev Weiss X-Patchwork-Id: 13108933 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1B26AC004D4 for ; Thu, 19 Jan 2023 23:00:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230119AbjASXAY (ORCPT ); Thu, 19 Jan 2023 18:00:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230391AbjASW7a (ORCPT ); Thu, 19 Jan 2023 17:59:30 -0500 X-Greylist: delayed 602 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 19 Jan 2023 14:49:10 PST Received: from thorn.bewilderbeest.net (thorn.bewilderbeest.net [IPv6:2605:2700:0:5::4713:9cab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1755E4B4A8 for ; Thu, 19 Jan 2023 14:49:10 -0800 (PST) Received: from hatter.bewilderbeest.net (97-113-250-99.tukw.qwest.net [97.113.250.99]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: zev) by thorn.bewilderbeest.net (Postfix) with ESMTPSA id A62E2D43; Thu, 19 Jan 2023 14:39:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1674167948; bh=c7tpmlEJ9MOEqIs9Ny7WGHY0IiNufJ+tlox4ExGFt94=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lpI9sTj8rkltMrGqYIXFzybnJ4qzPgKt+kEflesCSRIN1jpApU1SD3XGD6aelnb8q U9oGHyXsn0bf5OepI0crjC/T+lc6oQqzeIym4EomajBWG7peyE6sMs4RTqcYcc8R1v +ivoth52IuRLzOb6xL5TnRBv2jPn4irXC7ahn8mo= From: Zev Weiss To: git@vger.kernel.org Cc: Zev Weiss , Emma Brooks , Hamza Mahfooz , Junio C Hamano Subject: [PATCH 4/5] pretty: Add name_and_address_only parameter Date: Thu, 19 Jan 2023 14:38:57 -0800 Message-Id: <20230119223858.29262-5-zev@bewilderbeest.net> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230119223858.29262-1-zev@bewilderbeest.net> References: <20230119223858.29262-1-zev@bewilderbeest.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org 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 --- 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;