From patchwork Fri Aug 26 21:32:02 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: 12956600 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 9D0CCECAAD8 for ; Fri, 26 Aug 2022 21:32:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237812AbiHZVcI (ORCPT ); Fri, 26 Aug 2022 17:32:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230416AbiHZVcG (ORCPT ); Fri, 26 Aug 2022 17:32:06 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19BD0923FA for ; Fri, 26 Aug 2022 14:32:06 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id y1so791583plb.2 for ; Fri, 26 Aug 2022 14:32:06 -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; bh=gp4Utx1sI2y7ZuD9NMqTEKuMaahJwBIYZx52Hfiwbzw=; b=kfZ1+uW9m/MV0zOvIUkmJT1gyed/H/iahYmYA9F6xze663CM1Q72jxr58PgMbRT7G8 2TjYt6ElMJOplGZAmC85af9MJNYgZrgdCpMo5aXc2c5p6LAJuMmaz8jePHgmzohQbavz RCzErhbFqS+kTBpfVnWWs8YVLZgQsT7oQ4hlttDrPKLM5gO68RNHnAFfDDO9MV3bALzU ShSMxz9ZfRp4S25LKivF8hi8po92JOPMsla9rKVsQW+upG8wHfHzgUEOQj8Vnt05EQ0x 6Sq20AU5+yuIFa2NL7SoNBzU2OhrBZJAmjt07w1Qpq1KM01HuoXgDAPMHhCOilE9vltf GscA== 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; bh=gp4Utx1sI2y7ZuD9NMqTEKuMaahJwBIYZx52Hfiwbzw=; b=WL7PX6B43Y3J6qVcyLOKbdccmzHJJWDS+C49LGlMPWSx4UA06ENn1jx/wVMq7nhJ5P 4cUTIGZqG9vosFBA1FXmWJ3eEjEUpOkxbhoS7kHtsb8N81YmZY7LguTMujHYkpm0jWNR 5sGQRa4cP2kDRDWi3tGWS2esu3rZQVqrT26oluvMVTuJKDdm7hcRQLGScjwXdeZl9ho/ bogSkF/Ud/Ddk5NRDNJg9g+lZHMX2Zeu7QGxVbFpi2d1ttYDdr3VFmUEiEAgLTVm1ttz I8wj0botvO6++0UiLUzkEgBhn0lRlNgN3K4l2PBgtCTZ4OnmqE1iNeCPWn7SReAt6T+m Y2WQ== X-Gm-Message-State: ACgBeo1DoYXZt0tpBIuLCcQ2kK3ocFJRZwKxyqDElCvqggyJP3QD/7eY OZUctqBTl3F5+oGek4aaI1BwMu2lE0c= X-Google-Smtp-Source: AA6agR7ZHlIpOE0Quv1shLLrgfjJdPoxmcho3nPtTp/E1AWFc/ji/DgdU6EFt7c/ZglkGaudBcOK4Q== X-Received: by 2002:a17:902:7b87:b0:172:8ae9:2015 with SMTP id w7-20020a1709027b8700b001728ae92015mr5593909pll.112.1661549525231; Fri, 26 Aug 2022 14:32:05 -0700 (PDT) Received: from localhost (33.5.83.34.bc.googleusercontent.com. [34.83.5.33]) by smtp.gmail.com with ESMTPSA id m1-20020a1709026bc100b00172d9f6e22bsm2067929plt.15.2022.08.26.14.32.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Aug 2022 14:32:04 -0700 (PDT) Sender: Junio C Hamano From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH 1/2] pretty: separate out the logic to decide the use of in-body from Date: Fri, 26 Aug 2022 14:32:02 -0700 Message-Id: <20220826213203.3258022-2-gitster@pobox.com> X-Mailer: git-send-email 2.37.2-587-g47adba97a9 In-Reply-To: <20220826213203.3258022-1-gitster@pobox.com> References: <20220826213203.3258022-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 e-mail format (e.g. "git format-patch"), we add in-body "From:" header when the author identity of the commit is different from the identity of the person who is "sending" the mail. Split out the logic into a helper function. Because the "from_ident must be set" condition is there not because it is used in the ident_cmp() next, but because the codepath that is entered when this logic says "Yes, you should use in-body from" requires values there in from_ident member, so separate it out into an if() statement on its own to clarify it. Signed-off-by: Junio C Hamano --- pretty.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pretty.c b/pretty.c index 6d819103fb..51e3fa5736 100644 --- a/pretty.c +++ b/pretty.c @@ -477,6 +477,15 @@ static void append_line_with_color(struct strbuf *sb, struct grep_opt *opt, } } +static int use_inbody_from(const struct pretty_print_context *pp, const struct ident_split *ident) +{ + if (!pp->from_ident) + return 0; + 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 +512,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 (use_inbody_from(pp, &ident)) { struct strbuf buf = STRBUF_INIT; strbuf_addstr(&buf, "From: "); From patchwork Fri Aug 26 21:32:03 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: 12956602 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 18417C0502A for ; Fri, 26 Aug 2022 21:32:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231760AbiHZVcL (ORCPT ); Fri, 26 Aug 2022 17:32:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241925AbiHZVcJ (ORCPT ); Fri, 26 Aug 2022 17:32:09 -0400 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18EF89080A for ; Fri, 26 Aug 2022 14:32:07 -0700 (PDT) Received: by mail-pg1-x52d.google.com with SMTP id v4so2461030pgi.10 for ; Fri, 26 Aug 2022 14:32:07 -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; bh=XacwkKk0dK8hGgYR0KtjQxOYY3PmGw7qCiiw8w48xb0=; b=OcceCbghR1FxOOoAJ5ubhcTw5vXOmQHWwQ2vpwjJ/OFyWK4wzMFhXh6CjiEJoivKYM gD0mBJFx5X/Tk5VO9YPo7O/STYpARxBSOpJuNkxxpeBbZY0X8iMUoWEAegfXQkRZI+ZG tU2o0qP8VzCpIcAIWOWo7pihsU+XFUAeqRg9xdzIi0FwMaAMFhaEreEGh8rEQAFx53G1 J4an2tcOhdqX2zMMSJSX5IenbWz0mvc1eANLN0wFyGV/18GLKHz6PEjzrAtkml9NlZ4E GuiP13e+PW3esiHvDClZfTpuNl6wY8rkQKDkXqm3kLw1A014gmFg3hOtJJJGGk7mFbtD lYfg== 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; bh=XacwkKk0dK8hGgYR0KtjQxOYY3PmGw7qCiiw8w48xb0=; b=kGLdSQ1UurVyzUjT43aKMTu51LWrQsMAEdFp6PkA4iKbhgjFh49xGWYT5hc3i5EO5G uRMQSEu5ZRKg7HbLGJxe9LoP+/02JgRJ9NNaWifttdaRidFHXIHuYqW0P56OjOVqGYxB 9sHo9EPIxv6zOIl9rp9MM6eSD4ySJHa2LIK6ClEJKTdvasjZvwpj/tXiOowDgC3tWZ7z dSa3KSXlfEKwW6712gccavsZnkTwlLr55hFSezlwByrqazFX1e/W+lWc/9sONwwQfBWK oF0qTLieCJK2Zb8BaJzov5s36TzJ8jkyXE57OFDjICmAlyUjHTXmGeJhzC0DuP8UpDRG gCmQ== X-Gm-Message-State: ACgBeo1Xg27WNFLvIigVscuSt2lD6FaAsddP4nECB/Iqvv6mDco2sSWK 4cKSvRnausdpftuKAK8vqkazDdHbsCE= X-Google-Smtp-Source: AA6agR5MFNayv1T0u8HtcLvhUs6v4WlFA6FnyJ97zKNEuOjCFeMlas10HBy1Zfyg8xMvqzmEwpqOUw== X-Received: by 2002:a65:6385:0:b0:429:f03c:d5e with SMTP id h5-20020a656385000000b00429f03c0d5emr4766251pgv.322.1661549526235; Fri, 26 Aug 2022 14:32:06 -0700 (PDT) Received: from localhost (33.5.83.34.bc.googleusercontent.com. [34.83.5.33]) by smtp.gmail.com with ESMTPSA id c8-20020a170903234800b0016d3935eff0sm36487plh.176.2022.08.26.14.32.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Aug 2022 14:32:05 -0700 (PDT) Sender: Junio C Hamano From: Junio C Hamano To: git@vger.kernel.org Subject: [PATCH 2/2] format-patch: allow forcing the use of in-body From: header Date: Fri, 26 Aug 2022 14:32:03 -0700 Message-Id: <20220826213203.3258022-3-gitster@pobox.com> X-Mailer: git-send-email 2.37.2-587-g47adba97a9 In-Reply-To: <20220826213203.3258022-1-gitster@pobox.com> References: <20220826213203.3258022-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 an unfortunate situation, the user may want to add the in-body "From:" header even for their own patch. "git format-patch --[no-]force-inbody-from" was invented for such users. Note. This is an uncooked early draft. Things to think about include (but not limited to, of course): * Should this rather be --use-inbody-from=yes,no,auto tristate, that defaults to "auto", which is the current behaviour i.e. "when --from is given, add it only when it does not match the payload". "yes" would mean "always emit the --from address as in-body From:" and "no" would mean ... what? "Ignore --from"? Then why is the user giving --from in the first place? * Should it be "inbody" or "in-body"? * Should it have a corresponding configuration variable? * Should this patch be scrapped and the feature should be done inside "git send-email" instead? Signed-off-by: Junio C Hamano --- builtin/log.c | 2 ++ pretty.c | 2 ++ revision.h | 1 + t/t4014-format-patch.sh | 13 +++++++++++++ 4 files changed, 18 insertions(+) diff --git a/builtin/log.c b/builtin/log.c index 9b937d59b8..83b2d01b49 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -1897,6 +1897,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-inbody-from", &rev.force_inbody_from, + N_("Use in-body From: even for your own commit")), OPT_END() }; diff --git a/pretty.c b/pretty.c index 51e3fa5736..e266208c0b 100644 --- a/pretty.c +++ b/pretty.c @@ -483,6 +483,8 @@ static int use_inbody_from(const struct pretty_print_context *pp, const struct i return 0; if (ident_cmp(pp->from_ident, ident)) return 1; + if (pp->rev && pp->rev->force_inbody_from) + return 1; return 0; } diff --git a/revision.h b/revision.h index bb91e7ed91..a2d3813a21 100644 --- a/revision.h +++ b/revision.h @@ -208,6 +208,7 @@ struct rev_info { /* Format info */ int show_notes; + unsigned int force_inbody_from; unsigned int shown_one:1, shown_dashes:1, show_merge:1, diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index fbec8ad2ef..a4ecd433e2 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-inbody-from, --from keeps redundant in-body header' ' + git format-patch --force-inbody-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^" &&