8 static int initialized;
10 void get_commit_notes(const struct commit *commit, struct strbuf *sb,
11 const char *output_encoding)
13 static const char *utf8 = "utf-8";
14 struct strbuf name = STRBUF_INIT;
16 unsigned char sha1[20];
18 unsigned long msgoffset, msglen;
19 enum object_type type;
22 const char *env = getenv(GIT_NOTES_REF_ENVIRONMENT);
24 notes_ref_name = getenv(GIT_NOTES_REF_ENVIRONMENT);
25 else if (!notes_ref_name)
26 notes_ref_name = GIT_NOTES_DEFAULT_REF;
27 if (notes_ref_name && read_ref(notes_ref_name, sha1))
28 notes_ref_name = NULL;
35 strbuf_addf(&name, "%s:%s", notes_ref_name,
36 sha1_to_hex(commit->object.sha1));
37 if (get_sha1(name.buf, sha1))
40 if (!(msg = read_sha1_file(sha1, &type, &msglen)) || !msglen ||
44 if (output_encoding && *output_encoding &&
45 strcmp(utf8, output_encoding)) {
46 char *reencoded = reencode_string(msg, output_encoding, utf8);
54 /* we will end the annotation by a newline anyway */
55 if (msglen && msg[msglen - 1] == '\n')
58 strbuf_addstr(sb, "\nNotes:\n");
60 for (msgoffset = 0; msgoffset < msglen;) {
61 int linelen = strchrnul(msg, '\n') - msg;
63 strbuf_addstr(sb, " ");
64 strbuf_add(sb, msg + msgoffset, linelen);