| 514 | } |
| 515 | |
| 516 | int parse_commit_buffer(struct repository *r, struct commit *item, const void *buffer, unsigned long size, int check_graph) |
| 517 | { |
| 518 | const char *tail = buffer; |
| 519 | const char *bufptr = buffer; |
| 520 | struct object_id parent; |
| 521 | struct commit_list **pptr; |
| 522 | struct commit_graft *graft; |
| 523 | const int tree_entry_len = the_hash_algo->hexsz + 5; |
| 524 | const int parent_entry_len = the_hash_algo->hexsz + 7; |
| 525 | struct tree *tree; |
| 526 | |
| 527 | if (item->object.parsed) |
| 528 | return 0; |
| 529 | /* |
| 530 | * Presumably this is leftover from an earlier failed parse; |
| 531 | * clear it out in preparation for us re-parsing (we'll hit the |
| 532 | * same error, but that's good, since it lets our caller know |
| 533 | * the result cannot be trusted. |
| 534 | */ |
| 535 | commit_list_free(item->parents); |
| 536 | item->parents = NULL; |
| 537 | |
| 538 | tail += size; |
| 539 | if (tail <= bufptr + tree_entry_len + 1 || memcmp(bufptr, "tree ", 5) || |
| 540 | bufptr[tree_entry_len] != '\n') |
| 541 | return error("bogus commit object %s", oid_to_hex(&item->object.oid)); |
| 542 | if (get_oid_hex(bufptr + 5, &parent) < 0) |
| 543 | return error("bad tree pointer in commit %s", |
| 544 | oid_to_hex(&item->object.oid)); |
| 545 | tree = lookup_tree(r, &parent); |
| 546 | if (!tree) |
| 547 | return error("bad tree pointer %s in commit %s", |
| 548 | oid_to_hex(&parent), |
| 549 | oid_to_hex(&item->object.oid)); |
| 550 | set_commit_tree(item, tree); |
| 551 | bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */ |
| 552 | pptr = &item->parents; |
| 553 | |
| 554 | graft = lookup_commit_graft(r, &item->object.oid); |
| 555 | if (graft) |
| 556 | r->parsed_objects->substituted_parent = 1; |
| 557 | while (bufptr + parent_entry_len < tail && !memcmp(bufptr, "parent ", 7)) { |
| 558 | struct commit *new_parent; |
| 559 | |
| 560 | if (tail <= bufptr + parent_entry_len + 1 || |
| 561 | get_oid_hex(bufptr + 7, &parent) || |
| 562 | bufptr[parent_entry_len] != '\n') |
| 563 | return error("bad parents in commit %s", oid_to_hex(&item->object.oid)); |
| 564 | bufptr += parent_entry_len + 1; |
| 565 | /* |
| 566 | * The clone is shallow if nr_parent < 0, and we must |
| 567 | * not traverse its real parents even when we unhide them. |
| 568 | */ |
| 569 | if (graft && (graft->nr_parent < 0 || !grafts_keep_true_parents)) |
| 570 | continue; |
| 571 | new_parent = lookup_commit(r, &parent); |
| 572 | if (!new_parent) |
| 573 | return error("bad parent %s in commit %s", |
no test coverage detected