From patchwork Mon Aug 29 21:38:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 12958470 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 424EEECAAD4 for ; Mon, 29 Aug 2022 21:38:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229765AbiH2Vis (ORCPT ); Mon, 29 Aug 2022 17:38:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229784AbiH2Vik (ORCPT ); Mon, 29 Aug 2022 17:38:40 -0400 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E3F580F76 for ; Mon, 29 Aug 2022 14:38:39 -0700 (PDT) Received: by mail-pg1-x529.google.com with SMTP id r69so8894395pgr.2 for ; Mon, 29 Aug 2022 14:38:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:from:to:cc:subject:date; bh=jr7BwHTVU/SQNOtkb/4fbBnH/KiuQEe4iBSFUJBmJjY=; b=qw3Uom1w234bb34VRUnNXWzzcKfYpbpxnOrdQEreXpCy2unH7fm4wg6pwJb50Vhq6p ZMnXf/USB3GtgmVc5ucdJbmTTxKg28mvFa1Kd0WZG5eb2wY5F0rPoErLwB7tShk0T+Jj xUREMchxur508jusLry3x+4LWSy8AXzFE4DpKREBHSgx25YszKlMOPytrNKAKt/s9f6J taUsRSNZlvU8I8uY78nwEnLROMjZnXWbDY1xUkRili0CbwlJftworXQ4uHRpsZUiIBeW 7+i29Ao0VfRwdUuTzWC3aRlxWTQzBqUYXNwyuU70WVeHAC+D7yyMQADfZCeg3D4RNK0T SM2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:x-gm-message-state:from:to :cc:subject:date; bh=jr7BwHTVU/SQNOtkb/4fbBnH/KiuQEe4iBSFUJBmJjY=; b=VtCY30EmCYNAcvtGlerGEGznBYh3VOWZMiJ1F+NQKnpXN1VsZkqTx+xhKwlLbXjKGt 9+sIljcQxqwAoo/qwu29AajmLotB7fMFjEsMQgYPMm65QmVs+qUapMKzPC+huRveDZLN yMvRQYpUqYbSTfXQ5dujcSH+/f12J7v4IJn9ncTkfXUmVongNPgDf5O0xGNrmaZQKd/6 Q3MAmXRizLy/kc0gLGidwySCMxa+9K8cWletXsaeKELdG0f6mIOGtgL/RO5vh5YbVFNs uHFDspHqvqDJOuL3eCdRnnbzfQ7C/8Bux0SpXTWTLalJQ2ZWjfO+4MBOaV2QB9I8cdck Yvcg== X-Gm-Message-State: ACgBeo39+5Cno4pwQUIxxHJNHwUzG5T+zhw9sxTti1zoSp/w+NW5Zklu NZdcV1gQu/Xw+Mr+T3vtFkRhg8YvsSM= X-Google-Smtp-Source: AA6agR5VVtTsOVe75v0q8kRmMAnyldqr6aNJh6qkGHqJaifdLM4XMkde8xdZlHssW3//YFAWmMSVBA== X-Received: by 2002:a65:6a83:0:b0:42b:344a:3546 with SMTP id q3-20020a656a83000000b0042b344a3546mr15705096pgu.612.1661809118638; Mon, 29 Aug 2022 14:38:38 -0700 (PDT) Received: from localhost (33.5.83.34.bc.googleusercontent.com. [34.83.5.33]) by smtp.gmail.com with ESMTPSA id i22-20020a631316000000b0041c30f78fa6sm150561pgl.69.2022.08.29.14.38.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Aug 2022 14:38:38 -0700 (PDT) Sender: Junio C Hamano From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v2 1/3] pretty: separate out the logic to decide the use of in-body from Date: Mon, 29 Aug 2022 14:38:35 -0700 Message-Id: <20220829213837.13849-2-gitster@pobox.com> X-Mailer: git-send-email 2.37.2-621-gd3a800faf0 In-Reply-To: <20220829213837.13849-1-gitster@pobox.com> References: <20220826213203.3258022-1-gitster@pobox.com> <20220829213837.13849-1-gitster@pobox.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When pretty-printing the log message for a given commit in the e-mail format (e.g. "git format-patch"), we add an in-body "From:" header when the author identity of the commit is different from the identity of the person whose identity appears in the header of the e-mail (the latter is passed with them "--from" option). Split out the logic into a helper function, as we would want to extend the condition further. Signed-off-by: Junio C Hamano --- pretty.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pretty.c b/pretty.c index 6d819103fb..cf418a6b20 100644 --- a/pretty.c +++ b/pretty.c @@ -477,6 +477,14 @@ static void append_line_with_color(struct strbuf *sb, struct grep_opt *opt, } } +static int use_in_body_from(const struct pretty_print_context *pp, + const struct ident_split *ident) +{ + if (ident_cmp(pp->from_ident, ident)) + return 1; + return 0; +} + void pp_user_info(struct pretty_print_context *pp, const char *what, struct strbuf *sb, const char *line, const char *encoding) @@ -503,7 +511,7 @@ void pp_user_info(struct pretty_print_context *pp, map_user(pp->mailmap, &mailbuf, &maillen, &namebuf, &namelen); if (cmit_fmt_is_mail(pp->fmt)) { - if (pp->from_ident && ident_cmp(pp->from_ident, &ident)) { + if (pp->from_ident && use_in_body_from(pp, &ident)) { struct strbuf buf = STRBUF_INIT; strbuf_addstr(&buf, "From: "); From patchwork Mon Aug 29 21:38:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 12958471 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 4CABCECAAD2 for ; Mon, 29 Aug 2022 21:38:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229770AbiH2Viu (ORCPT ); Mon, 29 Aug 2022 17:38:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229813AbiH2Vil (ORCPT ); Mon, 29 Aug 2022 17:38:41 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A816D816B2 for ; Mon, 29 Aug 2022 14:38:40 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id q15so4087442pfn.11 for ; Mon, 29 Aug 2022 14:38:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:from:to:cc:subject:date; bh=j/MfIrQY4laDXr69h8Jg/zDjk2oNKxg1wyWNe1Ccfjc=; b=lXOSXCk3GelFzIljLJgC/ebHdKJlI5MsvnwhjGH0i3yeh0fyvX5C+WKdyCVcEF7by3 r7C1aDpA/ugOGyzDeFYe7xo5yZqf5xkYvx2kCoB5f9TKAZPXHPcYV3ZtQUOxxMnyAB4X r2bq+XV4zIZ+Qr0t366TY1T+9GxEhqtCAnHEgH96uyjggqaGFmECLdwygvQ2LfN9TrHd DTV+ctQggLz+14w1EnhZKcV/EJx5TYbOJdNA2F85PgTLTOO9TQwyMcQwrvoiDpkwgLRw F10+C1XNAaVYNm4G6kL8y3fjKjWL+tR1V4REe3SskLl/s1bLJHWND+mhu5mw+GoqXLTl nY3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:x-gm-message-state:from:to :cc:subject:date; bh=j/MfIrQY4laDXr69h8Jg/zDjk2oNKxg1wyWNe1Ccfjc=; b=mmXe5cymCu6jIfeTZv26FiAyzNf+PJ0raBPXqLZhzClR3CMkwZycOfWzR2/rF/TV0J f1N/oEhHMkLrKEeNrMt/VMxEa8pZ2gMeSH5b6wyTGakslkpqLMTVj5yfuHkRZbbo9966 kn6qHnIGyil6tTvzfvNVbnBiV0M61PwqBAqcllxbbfXP+V2uJc9leJfC3GtM3xKTbKk8 88f08r6fFQYXmA9JWwmCs4GntPdkV6ftdw+YixDPKupVPgqgVXDAPCJ2Z2fWF+TojUyy Bi2eXTXHulEZvTdt5aqAs7baOXEqxDpAB7u9tltLjqKS+Y4z/ukB+qGkVaNxXi7fERHo W4gw== X-Gm-Message-State: ACgBeo2H+eM4CpyXiRg23C4Q8VPeY0Q3JbyLohyADqm8QenaCxkAZKEO /w9xPXRYg8j3szS0bW3nmqBZFhZKbDc= X-Google-Smtp-Source: AA6agR6JFPxpm4Jqsg2M70FqGDr6yQBaf/ug7g6R8YiBVb39c9oDo2r8G+xBeA+c4JbJwaDyuTlLjA== X-Received: by 2002:a65:6491:0:b0:42a:c39a:e58e with SMTP id e17-20020a656491000000b0042ac39ae58emr15221797pgv.68.1661809119810; Mon, 29 Aug 2022 14:38:39 -0700 (PDT) Received: from localhost (33.5.83.34.bc.googleusercontent.com. [34.83.5.33]) by smtp.gmail.com with ESMTPSA id w85-20020a627b58000000b00535d094d6ecsm7775014pfc.108.2022.08.29.14.38.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Aug 2022 14:38:38 -0700 (PDT) Sender: Junio C Hamano From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v2 2/3] format-patch: allow forcing the use of in-body From: header Date: Mon, 29 Aug 2022 14:38:36 -0700 Message-Id: <20220829213837.13849-3-gitster@pobox.com> X-Mailer: git-send-email 2.37.2-621-gd3a800faf0 In-Reply-To: <20220829213837.13849-1-gitster@pobox.com> References: <20220826213203.3258022-1-gitster@pobox.com> <20220829213837.13849-1-gitster@pobox.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Users may be authoring and committing their commits under the same e-mail address they use to send their patches from, in which case they shouldn't need to use the in-body From: line in their outgoing e-mails. At the receiving end, "git am" will use the address on the "From:" header of the incoming e-mail and all should be well. Some mailing lists, however, mangle the From: address from what the original sender had; in such a situation, the user may want to add the in-body "From:" header even for their own patches. "git format-patch --[no-]force-in-body-from" was invented for such users. Signed-off-by: Junio C Hamano --- Documentation/git-format-patch.txt | 9 +++++++++ builtin/log.c | 5 +++++ pretty.c | 2 ++ revision.h | 1 + t/t4014-format-patch.sh | 13 +++++++++++++ 5 files changed, 30 insertions(+) diff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt index be797d7a28..7c7f244e57 100644 --- a/Documentation/git-format-patch.txt +++ b/Documentation/git-format-patch.txt @@ -275,6 +275,15 @@ header). Note also that `git send-email` already handles this transformation for you, and this option should not be used if you are feeding the result to `git send-email`. +--[no-]force-in-body-from:: + With the e-mail sender specified via the `--from` option, by + default, an in-body "From:" to identify the real author of + the commit is added at the top of the commit log message if + the sender is different from the author. With this option, + the in-body "From:" is added even when the sender and the + author have the same name and address, which may help if the + mailing list software mangles the sender's identity. + --add-header=
:: Add an arbitrary header to the email headers. This is in addition to any configured headers, and may be used multiple times. diff --git a/builtin/log.c b/builtin/log.c index 9b937d59b8..78ccd37bd9 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -52,6 +52,7 @@ static int default_encode_email_headers = 1; static int decoration_style; static int decoration_given; static int use_mailmap_config = 1; +static unsigned int force_in_body_from; static const char *fmt_patch_subject_prefix = "PATCH"; static int fmt_patch_name_max = FORMAT_PATCH_NAME_MAX_DEFAULT; static const char *fmt_pretty; @@ -1897,6 +1898,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) N_("show changes against in cover letter or single patch")), OPT_INTEGER(0, "creation-factor", &creation_factor, N_("percentage by which creation is weighted")), + OPT_BOOL(0, "force-in-body-from", &force_in_body_from, + N_("show in-body From: even if identical to the e-mail header")), OPT_END() }; @@ -1940,6 +1943,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN | PARSE_OPT_KEEP_DASHDASH); + rev.force_in_body_from = force_in_body_from; + /* Make sure "0000-$sub.patch" gives non-negative length for $sub */ if (fmt_patch_name_max <= strlen("0000-") + strlen(fmt_patch_suffix)) fmt_patch_name_max = strlen("0000-") + strlen(fmt_patch_suffix); diff --git a/pretty.c b/pretty.c index cf418a6b20..b7553e3fe0 100644 --- a/pretty.c +++ b/pretty.c @@ -480,6 +480,8 @@ static void append_line_with_color(struct strbuf *sb, struct grep_opt *opt, static int use_in_body_from(const struct pretty_print_context *pp, const struct ident_split *ident) { + if (pp->rev && pp->rev->force_in_body_from) + return 1; if (ident_cmp(pp->from_ident, ident)) return 1; return 0; diff --git a/revision.h b/revision.h index bb91e7ed91..6e346a60ab 100644 --- a/revision.h +++ b/revision.h @@ -221,6 +221,7 @@ struct rev_info { missing_newline:1, date_mode_explicit:1, preserve_subject:1, + force_in_body_from:1, encode_email_headers:1, include_header:1; unsigned int disable_stdin:1; diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index fbec8ad2ef..347f7f7f35 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -1400,6 +1400,19 @@ test_expect_success '--from omits redundant in-body header' ' test_cmp expect patch.head ' +test_expect_success 'with --force-in-body-from, redundant in-body from is kept' ' + git format-patch --force-in-body-from \ + -1 --stdout --from="A U Thor " >patch && + cat >expect <<-\EOF && + From: A U Thor + + From: A U Thor + + EOF + sed -ne "/^From:/p; /^$/p; /^---$/q" patch >patch.head && + test_cmp expect patch.head +' + test_expect_success 'in-body headers trigger content encoding' ' test_env GIT_AUTHOR_NAME="éxötìc" test_commit exotic && test_when_finished "git reset --hard HEAD^" && From patchwork Mon Aug 29 21:38:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Junio C Hamano X-Patchwork-Id: 12958472 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 5E731ECAAD8 for ; Mon, 29 Aug 2022 21:38:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229776AbiH2Viw (ORCPT ); Mon, 29 Aug 2022 17:38:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229819AbiH2Vim (ORCPT ); Mon, 29 Aug 2022 17:38:42 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85D7781B28 for ; Mon, 29 Aug 2022 14:38:41 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id x23so9234808pll.7 for ; Mon, 29 Aug 2022 14:38:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:from:to:cc:subject:date; bh=1n6L7d08RFYkk44tzzGfXzVIq5piqiUIfxM2dcOtShE=; b=aSVnW9aqmTi8PiCSOcZx3tHuL3AUrt6bsYunMVpiswKW6XeRtTckbrfAC1W7wdDmEF TvdSS9DXlFtiPQ7uiz2iimYmosXvY0blBoUGClXKRYbGLwklj9wP3VnbVimuGOkbtYvu OY70UAViNC7uM2KVuWqzOf2kTAMzFKB06ouHRPFo0gJXSl7L03TY5kKZKlQnSWluvcjm Kdbc0l4+triV/XZ6uz1rcNNxvMDPuLQ7SActqboynlsCZnGKsauidG3Hn2l/1aholHe0 ez3VZmAICo8TK/Ks4XvTgcQiRCgKYOUmF7e08EM8Q7ZV782gh4UCqvpzSvOL0N6FB+C7 fJJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:x-gm-message-state:from:to :cc:subject:date; bh=1n6L7d08RFYkk44tzzGfXzVIq5piqiUIfxM2dcOtShE=; b=wvoX4b+VrJVpiITg8wnLeWZKdzWxH+/xwsOIKF5pIm799nf7mQZUX0O4aiyt2erzse u1QJ9bV9uwAAq9ASefJO7/a2xOHA+UEkcGvWS3aJ+opnHvNP4iGUNVFjw/LDDh5ITMnE 1Zkf3Smf0gN4dX8SylH0VpTExHWz1pgiRYF0sZ28PHLm0FViETU1Q4Pm3XOn+JzLY6qe Y8aCj9f/dlmG7KQELdnnBGmPT1nQAxmuf3W4y7qUhmDmZM+FWHyQPTwzJQOXjtHnnodq NoY9y+ATjH9gRDFcmwnMMitHr8xn8reJkbnx9HSXRR3W+9NF2lo/c/LexakRdTiW7JeU mQCA== X-Gm-Message-State: ACgBeo2rm3YdKHyxd4/Z1b+vreSUDZHP9wNnKHN1ZbVwlDF+PoK3BbMO u3dj8JUp8wvBY7uoeXnnMAk1bpLIDgQ= X-Google-Smtp-Source: AA6agR5JhPfJAT8mHIS/A6Qbr+eTWR/vWPLpn2LlBma9cMIRfeLoU9FkcfHtvslwRa4OauV2pFq0sQ== X-Received: by 2002:a17:902:8ec8:b0:173:12cb:e6c1 with SMTP id x8-20020a1709028ec800b0017312cbe6c1mr18131107plo.64.1661809120753; Mon, 29 Aug 2022 14:38:40 -0700 (PDT) Received: from localhost (33.5.83.34.bc.googleusercontent.com. [34.83.5.33]) by smtp.gmail.com with ESMTPSA id o7-20020a170902d4c700b0017509940418sm631736plg.79.2022.08.29.14.38.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Aug 2022 14:38:40 -0700 (PDT) Sender: Junio C Hamano From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH v2 3/3] format-patch: learn format.forceInBodyFrom configuration variable Date: Mon, 29 Aug 2022 14:38:37 -0700 Message-Id: <20220829213837.13849-4-gitster@pobox.com> X-Mailer: git-send-email 2.37.2-621-gd3a800faf0 In-Reply-To: <20220829213837.13849-1-gitster@pobox.com> References: <20220826213203.3258022-1-gitster@pobox.com> <20220829213837.13849-1-gitster@pobox.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As the need to use the "--force-in-body-from" option primarily is tied to which mailing list the mails go to (and get their From: address mangled), it is likely that a user who needs to use this option once to interact with their upstream project needs to use it for all patches they send out. Add a configuration variable, suitable for setting in the local configuration file per repository, for this. Signed-off-by: Junio C Hamano --- Documentation/config/format.txt | 4 ++++ Documentation/git-format-patch.txt | 2 ++ builtin/log.c | 4 ++++ t/t4014-format-patch.sh | 24 ++++++++++++++++++++++++ 4 files changed, 34 insertions(+) diff --git a/Documentation/config/format.txt b/Documentation/config/format.txt index fdbc06a4d2..c7303d8d9f 100644 --- a/Documentation/config/format.txt +++ b/Documentation/config/format.txt @@ -15,6 +15,10 @@ format.from:: different. If set to a non-boolean value, format-patch uses that value instead of your committer identity. Defaults to false. +format.forceInBodyFrom:: + Provides the default value for the `--[no-]force-in-body-from` + option to format-patch. Defaults to false. + format.numbered:: A boolean which can enable or disable sequence numbers in patch subjects. It defaults to "auto" which enables it only if there diff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt index 7c7f244e57..dfcc7da4c2 100644 --- a/Documentation/git-format-patch.txt +++ b/Documentation/git-format-patch.txt @@ -283,6 +283,8 @@ feeding the result to `git send-email`. the in-body "From:" is added even when the sender and the author have the same name and address, which may help if the mailing list software mangles the sender's identity. + Defaults to the value of the `format.forceInBodyFrom` + configuration variable. --add-header=
:: Add an arbitrary header to the email headers. This is in addition diff --git a/builtin/log.c b/builtin/log.c index 78ccd37bd9..776bc9afdb 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -1007,6 +1007,10 @@ static int git_format_config(const char *var, const char *value, void *cb) from = NULL; return 0; } + if (!strcmp(var, "format.forceinbodyfrom")) { + force_in_body_from = git_config_bool(var, value); + return 0; + } if (!strcmp(var, "format.notes")) { int b = git_parse_maybe_bool(value); if (b < 0) diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index 347f7f7f35..ad5c029279 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -1413,6 +1413,30 @@ test_expect_success 'with --force-in-body-from, redundant in-body from is kept' test_cmp expect patch.head ' +test_expect_success 'format.forceInBodyFrom, equivalent to --force-in-body-from' ' + git -c format.forceInBodyFrom=yes format-patch \ + -1 --stdout --from="A U Thor " >patch && + cat >expect <<-\EOF && + From: A U Thor + + From: A U Thor + + EOF + sed -ne "/^From:/p; /^$/p; /^---$/q" patch >patch.head && + test_cmp expect patch.head +' + +test_expect_success 'format.forceInBodyFrom, equivalent to --force-in-body-from' ' + git -c format.forceInBodyFrom=yes format-patch --no-force-in-body-from \ + -1 --stdout --from="A U Thor " >patch && + cat >expect <<-\EOF && + From: A U Thor + + EOF + sed -ne "/^From:/p; /^$/p; /^---$/q" patch >patch.head && + test_cmp expect patch.head +' + test_expect_success 'in-body headers trigger content encoding' ' test_env GIT_AUTHOR_NAME="éxötìc" test_commit exotic && test_when_finished "git reset --hard HEAD^" &&