pretty: use fmt_output_email_subject()

Add the email-style subject prefix (e.g. "Subject: [PATCH] ") directly when it's needed instead of letting log_write_email_headers() prepare it in a static buffer in advance. This simplifies storage ownership and code flow. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Mar 1, 2017 at 12:37 UTC 6d167fd7ccb84f07a0bd57d8e188a651e913b158
6 files changed +15 -15
builtin/log.c
+3 -2
@@ -989,8 +989,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
989 open_next_file(NULL, rev->numbered_files ? NULL : "cover-letter", rev, quiet))
990 return;
991
992 - log_write_email_headers(rev, head, &pp.subject, &pp.after_subject,
993 - &need_8bit_cte);
992 + log_write_email_headers(rev, head, &pp.after_subject, &need_8bit_cte);
993
994 for (i = 0; !need_8bit_cte && i < nr; i++) {
995 const char *buf = get_commit_buffer(list[i], NULL);
@@ -1005,6 +1004,8 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
1004 msg = body;
1005 pp.fmt = CMIT_FMT_EMAIL;
1006 pp.date_mode.type = DATE_RFC2822;
1007 + pp.rev = rev;
1008 + pp.print_email_subject = 1;
1009 pp_user_info(&pp, NULL, &sb, committer, encoding);
1010 pp_title_line(&pp, &msg, &sb, encoding, need_8bit_cte);
1011 pp_remainder(&pp, &msg, &sb, 0);
builtin/shortlog.c
+1 -1
@@ -143,7 +143,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
143
144 ctx.fmt = CMIT_FMT_USERFORMAT;
145 ctx.abbrev = log->abbrev;
146 - ctx.subject = "";
146 + ctx.print_email_subject = 1;
147 ctx.after_subject = "";
148 ctx.date_mode.type = DATE_NORMAL;
149 ctx.output_encoding = get_log_output_encoding();
commit.h
+4 -2
@@ -142,21 +142,24 @@ static inline int cmit_fmt_is_mail(enum cmit_fmt fmt)
142 return (fmt == CMIT_FMT_EMAIL || fmt == CMIT_FMT_MBOXRD);
143 }
144
145 +struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */
146 +
147 struct pretty_print_context {
148 /*
149 * Callers should tweak these to change the behavior of pp_* functions.
150 */
151 enum cmit_fmt fmt;
152 int abbrev;
151 - const char *subject;
153 const char *after_subject;
154 int preserve_subject;
155 struct date_mode date_mode;
156 unsigned date_mode_explicit:1;
157 + int print_email_subject;
158 int expand_tabs_in_log;
159 int need_8bit_cte;
160 char *notes_message;
161 struct reflog_walk_info *reflog_info;
162 + struct rev_info *rev;
163 const char *output_encoding;
164 struct string_list *mailmap;
165 int color;
@@ -175,7 +178,6 @@ struct userformat_want {
178 };
179
180 extern int has_non_ascii(const char *text);
178 -struct rev_info; /* in revision.h, it circularly uses enum cmit_fmt */
181 extern const char *logmsg_reencode(const struct commit *commit,
182 char **commit_encoding,
183 const char *output_encoding);
log-tree.c
+3 -6
@@ -349,11 +349,9 @@ void fmt_output_email_subject(struct strbuf *sb, struct rev_info *opt)
349 }
350
351 void log_write_email_headers(struct rev_info *opt, struct commit *commit,
352 - const char **subject_p,
352 const char **extra_headers_p,
353 int *need_8bit_cte_p)
354 {
356 - static struct strbuf subject = STRBUF_INIT;
355 const char *extra_headers = opt->extra_headers;
356 const char *name = oid_to_hex(opt->zero_commit ?
357 &null_oid : &commit->object.oid);
@@ -415,9 +413,6 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
413 opt->diffopt.stat_sep = buffer;
414 strbuf_release(&filename);
415 }
418 - strbuf_reset(&subject);
419 - fmt_output_email_subject(&subject, opt);
420 - *subject_p = subject.buf;
416 *extra_headers_p = extra_headers;
417 }
418
@@ -602,8 +597,10 @@ void show_log(struct rev_info *opt)
597 */
598
599 if (cmit_fmt_is_mail(opt->commit_format)) {
605 - log_write_email_headers(opt, commit, &ctx.subject, &extra_headers,
600 + log_write_email_headers(opt, commit, &extra_headers,
601 &ctx.need_8bit_cte);
602 + ctx.rev = opt;
603 + ctx.print_email_subject = 1;
604 } else if (opt->commit_format != CMIT_FMT_USERFORMAT) {
605 fputs(diff_get_color_opt(&opt->diffopt, DIFF_COMMIT), opt->diffopt.file);
606 if (opt->commit_format != CMIT_FMT_ONELINE)
log-tree.h
-1
@@ -22,7 +22,6 @@ void format_decorations_extended(struct strbuf *sb, const struct commit *commit,
22 format_decorations_extended((strbuf), (commit), (color), " (", ", ", ")")
23 void show_decorations(struct rev_info *opt, struct commit *commit);
24 void log_write_email_headers(struct rev_info *opt, struct commit *commit,
25 - const char **subject_p,
25 const char **extra_headers_p,
26 int *need_8bit_cte_p);
27 void load_ref_decorations(int flags);
pretty.c
+4 -3
@@ -1590,8 +1590,9 @@ void pp_title_line(struct pretty_print_context *pp,
1590 pp->preserve_subject ? "\n" : " ");
1591
1592 strbuf_grow(sb, title.len + 1024);
1593 - if (pp->subject) {
1594 - strbuf_addstr(sb, pp->subject);
1593 + if (pp->print_email_subject) {
1594 + if (pp->rev)
1595 + fmt_output_email_subject(sb, pp->rev);
1596 if (needs_rfc2047_encoding(title.buf, title.len, RFC2047_SUBJECT))
1597 add_rfc2047(sb, title.buf, title.len,
1598 encoding, RFC2047_SUBJECT);
@@ -1801,7 +1802,7 @@ void pretty_print_commit(struct pretty_print_context *pp,
1802 }
1803
1804 pp_header(pp, encoding, commit, &msg, sb);
1804 - if (pp->fmt != CMIT_FMT_ONELINE && !pp->subject) {
1805 + if (pp->fmt != CMIT_FMT_ONELINE && !pp->print_email_subject) {
1806 strbuf_addch(sb, '\n');
1807 }
1808