From: Junio C Hamano <gitster@pobox.com>
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 [thread overview]
Message-ID: <20220826213203.3258022-2-gitster@pobox.com> (raw)
In-Reply-To: <20220826213203.3258022-1-gitster@pobox.com>
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 <gitster@pobox.com>
---
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: ");
--
2.37.2-587-g47adba97a9
next prev parent reply other threads:[~2022-08-26 21:32 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-26 21:32 [PATCH 0/2] format-patch --force-inbody-from Junio C Hamano
2022-08-26 21:32 ` Junio C Hamano [this message]
2022-08-29 11:32 ` [PATCH 1/2] pretty: separate out the logic to decide the use of in-body from Johannes Schindelin
2022-08-29 17:29 ` Junio C Hamano
2022-08-26 21:32 ` [PATCH 2/2] format-patch: allow forcing the use of in-body From: header Junio C Hamano
2022-08-29 11:48 ` Johannes Schindelin
2022-08-29 17:41 ` Junio C Hamano
2022-08-29 21:38 ` [PATCH v2 0/3] format-patch --force-in-body-from Junio C Hamano
2022-08-29 21:38 ` [PATCH v2 1/3] pretty: separate out the logic to decide the use of in-body from Junio C Hamano
2022-08-29 21:38 ` [PATCH v2 2/3] format-patch: allow forcing the use of in-body From: header Junio C Hamano
2022-08-30 20:07 ` Jeff King
2022-08-30 20:14 ` Jeff King
2022-08-29 21:38 ` [PATCH v2 3/3] format-patch: learn format.forceInBodyFrom configuration variable Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220826213203.3258022-2-gitster@pobox.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).