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

Function load_subtree

notes.c:397–502  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

395}
396
397static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
398 struct int_node *node, unsigned int n)
399{
400 struct object_id object_oid;
401 size_t prefix_len;
402 void *buf;
403 struct tree_desc desc;
404 struct name_entry entry;
405 const unsigned hashsz = the_hash_algo->rawsz;
406
407 buf = fill_tree_descriptor(the_repository, &desc, &subtree->val_oid);
408 if (!buf)
409 die("Could not read %s for notes-index",
410 oid_to_hex(&subtree->val_oid));
411
412 prefix_len = subtree->key_oid.hash[KEY_INDEX];
413 if (prefix_len >= hashsz)
414 BUG("prefix_len (%"PRIuMAX") is out of range", (uintmax_t)prefix_len);
415 if (prefix_len * 2 < n)
416 BUG("prefix_len (%"PRIuMAX") is too small", (uintmax_t)prefix_len);
417 memcpy(object_oid.hash, subtree->key_oid.hash, prefix_len);
418 while (tree_entry(&desc, &entry)) {
419 unsigned char type;
420 struct leaf_node *l;
421 size_t path_len = strlen(entry.path);
422
423 if (path_len == 2 * (hashsz - prefix_len)) {
424 /* This is potentially the remainder of the SHA-1 */
425
426 if (!S_ISREG(entry.mode))
427 /* notes must be blobs */
428 goto handle_non_note;
429
430 if (hex_to_bytes(object_oid.hash + prefix_len, entry.path,
431 hashsz - prefix_len))
432 goto handle_non_note; /* entry.path is not a SHA1 */
433
434 memset(object_oid.hash + hashsz, 0, GIT_MAX_RAWSZ - hashsz);
435
436 type = PTR_TYPE_NOTE;
437 } else if (path_len == 2) {
438 /* This is potentially an internal node */
439 size_t len = prefix_len;
440
441 if (!S_ISDIR(entry.mode))
442 /* internal nodes must be trees */
443 goto handle_non_note;
444
445 if (hex_to_bytes(object_oid.hash + len++, entry.path, 1))
446 goto handle_non_note; /* entry.path is not a SHA1 */
447
448 /*
449 * Pad the rest of the SHA-1 with zeros,
450 * except for the last byte, where we write
451 * the length:
452 */
453 memset(object_oid.hash + len, 0, hashsz - len - 1);
454 object_oid.hash[KEY_INDEX] = (unsigned char)len;

Callers 4

note_tree_searchFunction · 0.85
note_tree_insertFunction · 0.85
for_each_note_helperFunction · 0.85
init_notesFunction · 0.85

Calls 12

fill_tree_descriptorFunction · 0.85
oid_to_hexFunction · 0.85
hex_to_bytesFunction · 0.85
oidcpyFunction · 0.85
oid_set_algoFunction · 0.85
note_tree_insertFunction · 0.85
strbuf_addchFunction · 0.85
strbuf_addstrFunction · 0.85
add_non_noteFunction · 0.85
strbuf_detachFunction · 0.85
dieFunction · 0.70
tree_entryFunction · 0.70

Tested by

no test coverage detected