git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] pretty: use fmt_output_email_subject()

From
Jeff King <peff@peff.net>
Date
Mar 1, 2017, 19:32 UTC
Message-ID
<20170301193210.tgvnjgc2hfaeebqf@sigill.intra.peff.net>
In-Reply-To
<xmqqfuiwhnud.fsf@gitster.mtv.corp.google.com>
On Wed, Mar 01, 2017 at 10:08:10AM -0800, Junio C Hamano wrote:
Show 17 quoted lines
> >  	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
Previous: Junio C HamanoNext: Junio C Hamano
Message 8 of 13 in “format-patch subject-prefix gets truncated when using the --numbered flag”
  1. Adrian DudauFeb 28, 2017
  2. Junio C HamanoFeb 28, 2017
  3. Junio C HamanoFeb 28, 2017
  4. Jeff KingFeb 28, 2017
  5. Jeff KingFeb 28, 2017
  6. 2/2 pretty: use fmt_output_email_subject()René Scharfe, Mar 1, 2017
  7. Junio C HamanoMar 1, 2017
  8. Jeff KingMar 1, 2017
  9. Junio C HamanoMar 1, 2017
  10. Jeff KingMar 1, 2017
  11. Jeff KingMar 1, 2017
  12. René ScharfeMar 1, 2017
  13. 1/2 log-tree: factor out fmt_output_email_subject()René Scharfe, Mar 1, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.