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