git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: "René Scharfe" <l.s.r@web.de>,
	"Adrian Dudau" <Adrian.Dudau@enea.com>,
	"git@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: [PATCH 2/2] pretty: use fmt_output_email_subject()
Date: Wed, 1 Mar 2017 14:32:10 -0500	[thread overview]
Message-ID: <20170301193210.tgvnjgc2hfaeebqf@sigill.intra.peff.net> (raw)
In-Reply-To: <xmqqfuiwhnud.fsf@gitster.mtv.corp.google.com>

On Wed, Mar 01, 2017 at 10:08:10AM -0800, Junio C Hamano wrote:

> >  	strbuf_grow(sb, title.len + 1024);
> > -	if (pp->subject) {
> > -		strbuf_addstr(sb, pp->subject);
> > +	if (pp->print_email_subject) {
> > +		if (pp->rev)
> > +			fmt_output_email_subject(sb, pp->rev);
> 
> A hidden assumption this code makes is that anybody who does not
> want .rev (aka "doing it as part of format-patch that may want
> nr/total etc") does not want _any_ "Subject: ".  It obviously holds
> true in today's code (the one in shortlog-add-commit is the only one
> and it sets an empty string to .subject).
> 
> Does the loss of flexibility to the future callers matter, though?
> I cannot tell offhand.
> 
> Thanks.  Let's see what others think.

I would think that future callers would just need to provide a dummy
pp->rev. I guess that logic could be pushed down into
fmt_output_email_subject(), so that it skips looking at
opt->subject_prefix, etc, when "opt" is NULL, and just hits the
"Subject:" case arm.

I don't think it's a big deal, but it would be easy to fix now, like:

diff --git a/log-tree.c b/log-tree.c
index 4618dd04c..c73df6857 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -334,13 +334,13 @@ void fmt_output_commit(struct strbuf *filename,
 
 void fmt_output_email_subject(struct strbuf *sb, struct rev_info *opt)
 {
-	if (opt->total > 0) {
+	if (opt && opt->total > 0) {
 		strbuf_addf(sb, "Subject: [%s%s%0*d/%d] ",
 			    opt->subject_prefix,
 			    *opt->subject_prefix ? " " : "",
 			    digits_in_number(opt->total),
 			    opt->nr, opt->total);
-	} else if (opt->total == 0 && opt->subject_prefix && *opt->subject_prefix) {
+	} else if (opt && opt->total == 0 && opt->subject_prefix && *opt->subject_prefix) {
 		strbuf_addf(sb, "Subject: [%s] ",
 			    opt->subject_prefix);
 	} else {
diff --git a/pretty.c b/pretty.c
index d0f86f5d8..6b321c68c 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1608,8 +1608,7 @@ void pp_title_line(struct pretty_print_context *pp,
 
 	strbuf_grow(sb, title.len + 1024);
 	if (pp->print_email_subject) {
-		if (pp->rev)
-			fmt_output_email_subject(sb, pp->rev);
+		fmt_output_email_subject(sb, pp->rev);
 		if (needs_rfc2047_encoding(title.buf, title.len, RFC2047_SUBJECT))
 			add_rfc2047(sb, title.buf, title.len,
 						encoding, RFC2047_SUBJECT);

-Peff

  reply	other threads:[~2017-03-01 19:39 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-28 15:59 format-patch subject-prefix gets truncated when using the --numbered flag Adrian Dudau
2017-02-28 17:42 ` Junio C Hamano
2017-02-28 19:33   ` Junio C Hamano
2017-02-28 22:44     ` Jeff King
2017-02-28 18:17 ` Jeff King
2017-03-01 11:36   ` [PATCH 1/2] log-tree: factor out fmt_output_email_subject() René Scharfe
2017-03-01 11:37   ` [PATCH 2/2] pretty: use fmt_output_email_subject() René Scharfe
2017-03-01 15:41     ` René Scharfe
2017-03-01 18:08     ` Junio C Hamano
2017-03-01 19:32       ` Jeff King [this message]
2017-03-01 19:38         ` Junio C Hamano
2017-03-01 19:43           ` Jeff King
2017-03-01 19:22     ` Jeff King

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170301193210.tgvnjgc2hfaeebqf@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=Adrian.Dudau@enea.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=l.s.r@web.de \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).