Code

notes: fix core.notesRef documentation
[git.git] / pretty.c
index 8beafa08d3927e943a94279f5d776d6a45c673c5..2d2872f3b5707c63c056c7591948db261a13b011 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -6,6 +6,7 @@
 #include "string-list.h"
 #include "mailmap.h"
 #include "log-tree.h"
+#include "notes.h"
 
 static char *user_format;
 
@@ -234,7 +235,7 @@ static char *get_header(const struct commit *commit, const char *key)
 
 static char *replace_encoding_header(char *buf, const char *encoding)
 {
-       struct strbuf tmp;
+       struct strbuf tmp = STRBUF_INIT;
        size_t start, len;
        char *cp = buf;
 
@@ -250,7 +251,6 @@ static char *replace_encoding_header(char *buf, const char *encoding)
                return buf; /* should not happen but be defensive */
        len = cp + 1 - (buf + start);
 
-       strbuf_init(&tmp, 0);
        strbuf_attach(&tmp, buf, strlen(buf), strlen(buf) + 1);
        if (is_encoding_utf8(encoding)) {
                /* we have re-coded to UTF-8; drop the header */
@@ -784,6 +784,20 @@ void pp_remainder(enum cmit_fmt fmt,
        }
 }
 
+char *reencode_commit_message(const struct commit *commit, const char **encoding_p)
+{
+       const char *encoding;
+
+       encoding = (git_log_output_encoding
+                   ? git_log_output_encoding
+                   : git_commit_encoding);
+       if (!encoding)
+               encoding = "utf-8";
+       if (encoding_p)
+               *encoding_p = encoding;
+       return logmsg_reencode(commit, encoding);
+}
+
 void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
                         struct strbuf *sb, int abbrev,
                         const char *subject, const char *after_subject,
@@ -800,12 +814,7 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
                return;
        }
 
-       encoding = (git_log_output_encoding
-                   ? git_log_output_encoding
-                   : git_commit_encoding);
-       if (!encoding)
-               encoding = "utf-8";
-       reencoded = logmsg_reencode(commit, encoding);
+       reencoded = reencode_commit_message(commit, &encoding);
        if (reencoded) {
                msg = reencoded;
        }
@@ -873,5 +882,9 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,
         */
        if (fmt == CMIT_FMT_EMAIL && sb->len <= beginning_of_body)
                strbuf_addch(sb, '\n');
+
+       if (fmt != CMIT_FMT_ONELINE)
+               get_commit_notes(commit, sb, encoding);
+
        free(reencoded);
 }