MCPcopy Index your code
hub / github.com/git/git / format_note

Function format_note

notes.c:1280–1340  ·  view source on GitHub ↗

* Fill the given strbuf with the notes associated with the given object. * * If the given notes_tree structure is not initialized, it will be auto- * initialized to the default value (see documentation for init_notes() above). * If the given notes_tree is NULL, the internal/default notes_tree will be * used instead. * * (raw != 0) gives the %N userformat; otherwise, the note message is give

Source from the content-addressed store, hash-verified

1278 * for human consumption.
1279 */
1280static void format_note(struct notes_tree *t, const struct object_id *object_oid,
1281 struct strbuf *sb, const char *output_encoding, int raw)
1282{
1283 static const char utf8[] = "utf-8";
1284 const struct object_id *oid;
1285 char *msg, *msg_p;
1286 unsigned long linelen;
1287 size_t msglen;
1288 enum object_type type;
1289
1290 if (!t)
1291 t = &default_notes_tree;
1292 if (!t->initialized)
1293 init_notes(t, NULL, NULL, 0);
1294
1295 oid = get_note(t, object_oid);
1296 if (!oid)
1297 return;
1298
1299 if (!(msg = odb_read_object(the_repository->objects, oid, &type, &msglen)) ||
1300 type != OBJ_BLOB) {
1301 free(msg);
1302 return;
1303 }
1304
1305 if (output_encoding && *output_encoding &&
1306 !is_encoding_utf8(output_encoding)) {
1307 char *reencoded = reencode_string(msg, output_encoding, utf8);
1308 if (reencoded) {
1309 free(msg);
1310 msg = reencoded;
1311 msglen = strlen(msg);
1312 }
1313 }
1314
1315 /* we will end the annotation by a newline anyway */
1316 if (msglen && msg[msglen - 1] == '\n')
1317 msglen--;
1318
1319 if (!raw) {
1320 const char *ref = t->ref;
1321 if (!ref || !strcmp(ref, GIT_NOTES_DEFAULT_REF)) {
1322 strbuf_addstr(sb, "\nNotes:\n");
1323 } else {
1324 skip_prefix(ref, "refs/", &ref);
1325 skip_prefix(ref, "notes/", &ref);
1326 strbuf_addf(sb, "\nNotes (%s):\n", ref);
1327 }
1328 }
1329
1330 for (msg_p = msg; msg_p < msg + msglen; msg_p += linelen + 1) {
1331 linelen = strchrnul(msg_p, '\n') - msg_p;
1332
1333 if (!raw)
1334 strbuf_addstr(sb, " ");
1335 strbuf_add(sb, msg_p, linelen);
1336 strbuf_addch(sb, '\n');
1337 }

Callers 1

format_display_notesFunction · 0.85

Calls 9

init_notesFunction · 0.85
get_noteFunction · 0.85
odb_read_objectFunction · 0.85
is_encoding_utf8Function · 0.85
reencode_stringFunction · 0.85
strbuf_addstrFunction · 0.85
strbuf_addfFunction · 0.85
strbuf_addFunction · 0.85
strbuf_addchFunction · 0.85

Tested by

no test coverage detected