log-tree: show_log: make commentary block delimiting reusable

In patches generated by git-format-patch, the area below the "---" line following the commit message and before the actual 'diff' can be used for commentary which the patch author wants to convey to readers of the patch itself but not include in the commit message proper. By default, the commentary area is empty, however, the --notes option causes it to be populated with notes associated with the commit. In the future, other options may be added which also insert content into the commentary section. To accommodate this, factor out the logic which delimits commentary blocks from the commit message so that it can be re-used for upcoming optional inserted content. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Sunshine committed Jul 22, 2018 at 05:57 UTC 3fcc7a23a0b76bdac07b605a6afd6084ac543821
1 file changed +16 -7
log-tree.c
+16 -7
@@ -541,6 +541,16 @@ static int show_mergetag(struct rev_info *opt, struct commit *commit)
541 return for_each_mergetag(show_one_mergetag, commit, opt);
542 }
543
544 +static void next_commentary_block(struct rev_info *opt, struct strbuf *sb)
545 +{
546 + const char *x = opt->shown_dashes ? "\n" : "---\n";
547 + if (sb)
548 + strbuf_addstr(sb, x);
549 + else
550 + fputs(x, opt->diffopt.file);
551 + opt->shown_dashes = 1;
552 +}
553 +
554 void show_log(struct rev_info *opt)
555 {
556 struct strbuf msgbuf = STRBUF_INIT;
@@ -698,10 +708,8 @@ void show_log(struct rev_info *opt)
708
709 if ((ctx.fmt != CMIT_FMT_USERFORMAT) &&
710 ctx.notes_message && *ctx.notes_message) {
701 - if (cmit_fmt_is_mail(ctx.fmt)) {
702 - strbuf_addstr(&msgbuf, "---\n");
703 - opt->shown_dashes = 1;
704 - }
711 + if (cmit_fmt_is_mail(ctx.fmt))
712 + next_commentary_block(opt, &msgbuf);
713 strbuf_addstr(&msgbuf, ctx.notes_message);
714 }
715
@@ -765,9 +773,10 @@ int log_tree_diff_flush(struct rev_info *opt)
773
774 /*
775 * We may have shown three-dashes line early
768 - * between notes and the log message, in which
769 - * case we only want a blank line after the
770 - * notes without (an extra) three-dashes line.
776 + * between generated commentary (notes, etc.)
777 + * and the log message, in which case we only
778 + * want a blank line after the commentary
779 + * without (an extra) three-dashes line.
780 * Otherwise, we show the three-dashes line if
781 * we are showing the patch with diffstat, but
782 * in that case, there is no extra blank line