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
;
15 unsigned char sha1
[20];
17 unsigned long linelen
, msglen
;
18 enum object_type type
;
21 const char *env
= getenv(GIT_NOTES_REF_ENVIRONMENT
);
23 notes_ref_name
= getenv(GIT_NOTES_REF_ENVIRONMENT
);
24 else if (!notes_ref_name
)
25 notes_ref_name
= GIT_NOTES_DEFAULT_REF
;
26 if (notes_ref_name
&& read_ref(notes_ref_name
, sha1
))
27 notes_ref_name
= NULL
;
34 strbuf_addf(&name
, "%s:%s", notes_ref_name
,
35 sha1_to_hex(commit
->object
.sha1
));
36 if (get_sha1(name
.buf
, sha1
))
39 if (!(msg
= read_sha1_file(sha1
, &type
, &msglen
)) || !msglen
||
45 if (output_encoding
&& *output_encoding
&&
46 strcmp(utf8
, output_encoding
)) {
47 char *reencoded
= reencode_string(msg
, output_encoding
, utf8
);
55 /* we will end the annotation by a newline anyway */
56 if (msglen
&& msg
[msglen
- 1] == '\n')
59 strbuf_addstr(sb
, "\nNotes:\n");
61 for (msg_p
= msg
; msg_p
< msg
+ msglen
; msg_p
+= linelen
+ 1) {
62 linelen
= strchrnul(msg_p
, '\n') - msg_p
;
64 strbuf_addstr(sb
, " ");
65 strbuf_add(sb
, msg_p
, linelen
);
66 strbuf_addch(sb
, '\n');