| 598 | } |
| 599 | |
| 600 | int repo_parse_commit_internal(struct repository *r, |
| 601 | struct commit *item, |
| 602 | int quiet_on_missing, |
| 603 | int use_commit_graph) |
| 604 | { |
| 605 | enum object_type type; |
| 606 | void *buffer; |
| 607 | size_t size; |
| 608 | struct object_info oi = { |
| 609 | .typep = &type, |
| 610 | .sizep = &size, |
| 611 | .contentp = &buffer, |
| 612 | }; |
| 613 | /* |
| 614 | * Git does not support partial clones that exclude commits, so set |
| 615 | * OBJECT_INFO_SKIP_FETCH_OBJECT to fail fast when an object is missing. |
| 616 | */ |
| 617 | int flags = OBJECT_INFO_LOOKUP_REPLACE | OBJECT_INFO_SKIP_FETCH_OBJECT | |
| 618 | OBJECT_INFO_DIE_IF_CORRUPT; |
| 619 | int ret; |
| 620 | |
| 621 | if (!item) |
| 622 | return -1; |
| 623 | if (item->object.parsed) |
| 624 | return 0; |
| 625 | if (use_commit_graph && parse_commit_in_graph(r, item)) { |
| 626 | static int commit_graph_paranoia = -1; |
| 627 | |
| 628 | if (commit_graph_paranoia == -1) |
| 629 | commit_graph_paranoia = git_env_bool(GIT_COMMIT_GRAPH_PARANOIA, 0); |
| 630 | |
| 631 | if (commit_graph_paranoia && !odb_has_object(r->objects, &item->object.oid, 0)) { |
| 632 | unparse_commit(r, &item->object.oid); |
| 633 | return quiet_on_missing ? -1 : |
| 634 | error(_("commit %s exists in commit-graph but not in the object database"), |
| 635 | oid_to_hex(&item->object.oid)); |
| 636 | } |
| 637 | |
| 638 | return 0; |
| 639 | } |
| 640 | |
| 641 | if (odb_read_object_info_extended(r->objects, &item->object.oid, |
| 642 | &oi, flags) < 0) |
| 643 | return quiet_on_missing ? -1 : |
| 644 | error("Could not read %s", |
| 645 | oid_to_hex(&item->object.oid)); |
| 646 | if (type != OBJ_COMMIT) { |
| 647 | free(buffer); |
| 648 | return error("Object %s not a commit", |
| 649 | oid_to_hex(&item->object.oid)); |
| 650 | } |
| 651 | |
| 652 | ret = parse_commit_buffer(r, item, buffer, size, 0); |
| 653 | if (save_commit_buffer && !ret && |
| 654 | !get_cached_commit_buffer(r, item, NULL)) { |
| 655 | set_commit_buffer(r, item, buffer, size); |
| 656 | return 0; |
| 657 | } |
no test coverage detected