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>
Junio C Hamano committed
Oct 17, 2012 at 18:51 UTC
ddf333f66cb8b8647a40e5d39731eaf63ee9fd44
3 files changed
+18
-7
commit.h
+1
-1
@@ -86,7 +86,7 @@ struct pretty_print_context {
86
enum date_mode date_mode;
87
unsigned date_mode_explicit:1;
88
int need_8bit_cte;
89
- int show_notes;
89
+ char *notes_message;
90
struct reflog_walk_info *reflog_info;
91
const char *output_encoding;
92
};
log-tree.c
+13
-1
@@ -540,7 +540,6 @@ void show_log(struct rev_info *opt)
540
struct pretty_print_context ctx = {0};
541
542
opt->loginfo = NULL;
543
- ctx.show_notes = opt->show_notes;
543
if (!opt->verbose_header) {
544
graph_show_commit(opt->graph);
545
@@ -648,6 +647,18 @@ void show_log(struct rev_info *opt)
647
if (!commit->buffer)
648
return;
649
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, ¬ebuf,
656
+ get_log_output_encoding(), raw);
657
+ ctx.notes_message = notebuf.len
658
+ ? strbuf_detach(¬ebuf, NULL)
659
+ : xcalloc(1, 1);
660
+ }
661
+
662
/*
663
* And then the pretty-printed message itself
664
*/
@@ -689,6 +700,7 @@ void show_log(struct rev_info *opt)
700
}
701
702
strbuf_release(&msgbuf);
703
+ free(ctx.notes_message);
704
}
705
706
int log_tree_diff_flush(struct rev_info *opt)
pretty.c
+4
-5
@@ -1033,9 +1033,8 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
1033
}
1034
return 0; /* unknown %g placeholder */
1035
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);
1038
return 1;
1039
}
1040
return 0;
@@ -1418,8 +1417,8 @@ void pretty_print_commit(const struct pretty_print_context *pp,
1417
if (pp->fmt == CMIT_FMT_EMAIL && sb->len <= beginning_of_body)
1418
strbuf_addch(sb, '\n');
1419
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);
1422
1423
free(reencoded);
1424
}