pretty: prepare notes message at a centralized place
authorJunio C Hamano <gitster@pobox.com>
Thu, 18 Oct 2012 01:51:47 +0000 (18:51 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 18 Oct 2012 05:42:40 +0000 (22:42 -0700)
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>
commit.h
log-tree.c
pretty.c

index a822af8c8d6cc7a190acc666391c4636d10f497c..7b43e45017f9041cab074666a5813a5e666ae714 100644 (file)
--- a/commit.h
+++ b/commit.h
@@ -86,7 +86,7 @@ struct pretty_print_context {
        enum date_mode date_mode;
        unsigned date_mode_explicit:1;
        int need_8bit_cte;
-       int show_notes;
+       char *notes_message;
        struct reflog_walk_info *reflog_info;
        const char *output_encoding;
 };
index c894930c1863bfcf33a01b2d98c48478aa874186..84e9f5bb66bc6ed6f2a22d644437e6c9c1a617be 100644 (file)
@@ -540,7 +540,6 @@ void show_log(struct rev_info *opt)
        struct pretty_print_context ctx = {0};
 
        opt->loginfo = NULL;
-       ctx.show_notes = opt->show_notes;
        if (!opt->verbose_header) {
                graph_show_commit(opt->graph);
 
@@ -648,6 +647,18 @@ void show_log(struct rev_info *opt)
        if (!commit->buffer)
                return;
 
+       if (opt->show_notes) {
+               int raw;
+               struct strbuf notebuf = STRBUF_INIT;
+
+               raw = (opt->commit_format == CMIT_FMT_USERFORMAT);
+               format_display_notes(commit->object.sha1, &notebuf,
+                                    get_log_output_encoding(), raw);
+               ctx.notes_message = notebuf.len
+                       ? strbuf_detach(&notebuf, NULL)
+                       : xcalloc(1, 1);
+       }
+
        /*
         * And then the pretty-printed message itself
         */
@@ -689,6 +700,7 @@ void show_log(struct rev_info *opt)
        }
 
        strbuf_release(&msgbuf);
+       free(ctx.notes_message);
 }
 
 int log_tree_diff_flush(struct rev_info *opt)
index 735cf0fec3dd6882f9555855796ad3fa2af9d073..a53eb532aa5ae78b336d313ad46d4e5770c60092 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -1033,9 +1033,8 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
                }
                return 0;       /* unknown %g placeholder */
        case 'N':
-               if (c->pretty_ctx->show_notes) {
-                       format_display_notes(commit->object.sha1, sb,
-                                            get_log_output_encoding(), 1);
+               if (c->pretty_ctx->notes_message) {
+                       strbuf_addstr(sb, c->pretty_ctx->notes_message);
                        return 1;
                }
                return 0;
@@ -1418,8 +1417,8 @@ void pretty_print_commit(const struct pretty_print_context *pp,
        if (pp->fmt == CMIT_FMT_EMAIL && sb->len <= beginning_of_body)
                strbuf_addch(sb, '\n');
 
-       if (pp->show_notes)
-               format_display_notes(commit->object.sha1, sb, encoding, 0);
+       if (pp->notes_message && *pp->notes_message)
+               strbuf_addstr(sb, pp->notes_message);
 
        free(reencoded);
 }