| 295 | } |
| 296 | |
| 297 | static void export_blob(const struct object_id *oid) |
| 298 | { |
| 299 | unsigned long size; |
| 300 | enum object_type type; |
| 301 | char *buf; |
| 302 | struct object *object; |
| 303 | int eaten; |
| 304 | |
| 305 | if (no_data) |
| 306 | return; |
| 307 | |
| 308 | if (is_null_oid(oid)) |
| 309 | return; |
| 310 | |
| 311 | object = lookup_object(the_repository, oid); |
| 312 | if (object && object->flags & SHOWN) |
| 313 | return; |
| 314 | |
| 315 | if (anonymize) { |
| 316 | buf = anonymize_blob(&size); |
| 317 | object = (struct object *)lookup_blob(the_repository, oid); |
| 318 | eaten = 0; |
| 319 | } else { |
| 320 | size_t size_st = 0; |
| 321 | buf = odb_read_object(the_repository->objects, oid, &type, |
| 322 | &size_st); |
| 323 | size = cast_size_t_to_ulong(size_st); |
| 324 | if (!buf) |
| 325 | die(_("could not read blob %s"), oid_to_hex(oid)); |
| 326 | if (check_object_signature(the_repository, oid, buf, size, |
| 327 | type) < 0) |
| 328 | die(_("oid mismatch in blob %s"), oid_to_hex(oid)); |
| 329 | object = parse_object_buffer(the_repository, oid, type, |
| 330 | size, buf, &eaten); |
| 331 | } |
| 332 | |
| 333 | if (!object) |
| 334 | die(_("could not read blob %s"), oid_to_hex(oid)); |
| 335 | |
| 336 | mark_next_object(object); |
| 337 | |
| 338 | printf("blob\nmark :%"PRIu32"\n", last_idnum); |
| 339 | if (show_original_ids) |
| 340 | printf("original-oid %s\n", oid_to_hex(oid)); |
| 341 | printf("data %"PRIuMAX"\n", (uintmax_t)size); |
| 342 | if (size && fwrite(buf, size, 1, stdout) != 1) |
| 343 | die_errno(_("could not write blob '%s'"), oid_to_hex(oid)); |
| 344 | printf("\n"); |
| 345 | |
| 346 | show_progress(); |
| 347 | |
| 348 | object->flags |= SHOWN; |
| 349 | if (!eaten) |
| 350 | free(buf); |
| 351 | } |
| 352 | |
| 353 | static int depth_first(const void *a_, const void *b_) |
| 354 | { |
no test coverage detected