| 320 | } |
| 321 | |
| 322 | struct object *parse_object_with_flags(struct repository *r, |
| 323 | const struct object_id *oid, |
| 324 | enum parse_object_flags flags) |
| 325 | { |
| 326 | int skip_hash = !!(flags & PARSE_OBJECT_SKIP_HASH_CHECK); |
| 327 | int discard_tree = !!(flags & PARSE_OBJECT_DISCARD_TREE); |
| 328 | size_t size; |
| 329 | enum object_type type; |
| 330 | int eaten; |
| 331 | const struct object_id *repl = lookup_replace_object(r, oid); |
| 332 | void *buffer; |
| 333 | struct object *obj; |
| 334 | |
| 335 | obj = lookup_object(r, oid); |
| 336 | if (obj && obj->parsed) |
| 337 | return obj; |
| 338 | |
| 339 | if (skip_hash) { |
| 340 | struct commit *commit = lookup_commit_in_graph(r, repl); |
| 341 | if (commit) |
| 342 | return &commit->object; |
| 343 | } |
| 344 | |
| 345 | if ((!obj || obj->type == OBJ_NONE || obj->type == OBJ_BLOB) && |
| 346 | odb_read_object_info(r->objects, oid, NULL) == OBJ_BLOB) { |
| 347 | if (!skip_hash) { |
| 348 | struct odb_read_stream *stream = odb_read_stream_open(r->objects, oid, NULL); |
| 349 | |
| 350 | if (!stream) { |
| 351 | error(_("unable to open object stream for %s"), oid_to_hex(oid)); |
| 352 | return NULL; |
| 353 | } |
| 354 | |
| 355 | if (stream_object_signature(r, stream, repl) < 0) { |
| 356 | error(_("hash mismatch %s"), oid_to_hex(oid)); |
| 357 | odb_read_stream_close(stream); |
| 358 | return NULL; |
| 359 | } |
| 360 | |
| 361 | odb_read_stream_close(stream); |
| 362 | } |
| 363 | parse_blob_buffer(lookup_blob(r, oid)); |
| 364 | return lookup_object(r, oid); |
| 365 | } |
| 366 | |
| 367 | /* |
| 368 | * If the caller does not care about the tree buffer and does not |
| 369 | * care about checking the hash, we can simply verify that we |
| 370 | * have the on-disk object with the correct type. |
| 371 | */ |
| 372 | if (skip_hash && discard_tree && |
| 373 | (!obj || obj->type == OBJ_NONE || obj->type == OBJ_TREE) && |
| 374 | odb_read_object_info(r->objects, oid, NULL) == OBJ_TREE) { |
| 375 | return &lookup_tree(r, oid)->object; |
| 376 | } |
| 377 | |
| 378 | buffer = odb_read_object(r->objects, oid, &type, &size); |
| 379 | if (buffer) { |
no test coverage detected