| 395 | } |
| 396 | |
| 397 | static 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; |
no test coverage detected