Skip to content

Commit ddf333f

Browse files
committed
pretty: prepare notes message at a centralized place
Instead of passing a boolean show_notes around, pass an optional string that is to be inserted after the log message proper is shown. Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 76141e2 commit ddf333f

3 files changed

Lines changed: 18 additions & 7 deletions

File tree

‎commit.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ struct pretty_print_context {
8686
enum date_mode date_mode;
8787
unsigned date_mode_explicit:1;
8888
int need_8bit_cte;
89-
int show_notes;
89+
char *notes_message;
9090
struct reflog_walk_info *reflog_info;
9191
const char *output_encoding;
9292
};

‎log-tree.c‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,6 @@ void show_log(struct rev_info *opt)
540540
struct pretty_print_context ctx = {0};
541541

542542
opt->loginfo = NULL;
543-
ctx.show_notes = opt->show_notes;
544543
if (!opt->verbose_header) {
545544
graph_show_commit(opt->graph);
546545

@@ -648,6 +647,18 @@ void show_log(struct rev_info *opt)
648647
if (!commit->buffer)
649648
return;
650649

650+
if (opt->show_notes) {
651+
int raw;
652+
struct strbuf notebuf = STRBUF_INIT;
653+
654+
raw = (opt->commit_format == CMIT_FMT_USERFORMAT);
655+
format_display_notes(commit->object.sha1, &notebuf,
656+
get_log_output_encoding(), raw);
657+
ctx.notes_message = notebuf.len
658+
? strbuf_detach(&notebuf, NULL)
659+
: xcalloc(1, 1);
660+
}
661+
651662
/*
652663
* And then the pretty-printed message itself
653664
*/
@@ -689,6 +700,7 @@ void show_log(struct rev_info *opt)
689700
}
690701

691702
strbuf_release(&msgbuf);
703+
free(ctx.notes_message);
692704
}
693705

694706
int log_tree_diff_flush(struct rev_info *opt)

‎pretty.c‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,9 +1033,8 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
10331033
}
10341034
return 0; /* unknown %g placeholder */
10351035
case 'N':
1036-
if (c->pretty_ctx->show_notes) {
1037-
format_display_notes(commit->object.sha1, sb,
1038-
get_log_output_encoding(), 1);
1036+
if (c->pretty_ctx->notes_message) {
1037+
strbuf_addstr(sb, c->pretty_ctx->notes_message);
10391038
return 1;
10401039
}
10411040
return 0;
@@ -1418,8 +1417,8 @@ void pretty_print_commit(const struct pretty_print_context *pp,
14181417
if (pp->fmt == CMIT_FMT_EMAIL && sb->len <= beginning_of_body)
14191418
strbuf_addch(sb, '\n');
14201419

1421-
if (pp->show_notes)
1422-
format_display_notes(commit->object.sha1, sb, encoding, 0);
1420+
if (pp->notes_message && *pp->notes_message)
1421+
strbuf_addstr(sb, pp->notes_message);
14231422

14241423
free(reencoded);
14251424
}

0 commit comments

Comments
 (0)