Return 0 if we will bust the pack-size limit */
| 631 | |
| 632 | /* Return 0 if we will bust the pack-size limit */ |
| 633 | static off_t write_reuse_object(struct hashfile *f, struct object_entry *entry, |
| 634 | unsigned long limit, int usable_delta) |
| 635 | { |
| 636 | struct packed_git *p = IN_PACK(entry); |
| 637 | struct pack_window *w_curs = NULL; |
| 638 | uint32_t pos; |
| 639 | off_t offset, cur; |
| 640 | enum object_type type = oe_type(entry); |
| 641 | enum object_type in_pack_type; |
| 642 | off_t datalen; |
| 643 | unsigned char header[MAX_PACK_OBJECT_HEADER], |
| 644 | dheader[MAX_PACK_OBJECT_HEADER]; |
| 645 | unsigned hdrlen; |
| 646 | const unsigned hashsz = the_hash_algo->rawsz; |
| 647 | size_t entry_size; |
| 648 | |
| 649 | cur = entry->in_pack_offset; |
| 650 | in_pack_type = unpack_object_header(p, &w_curs, &cur, &entry_size); |
| 651 | if (in_pack_type < 0) |
| 652 | die(_("write_reuse_object: unable to parse object header of %s"), |
| 653 | oid_to_hex(&entry->idx.oid)); |
| 654 | |
| 655 | if (DELTA(entry)) |
| 656 | type = (allow_ofs_delta && DELTA(entry)->idx.offset) ? |
| 657 | OBJ_OFS_DELTA : OBJ_REF_DELTA; |
| 658 | hdrlen = encode_in_pack_object_header(header, sizeof(header), |
| 659 | type, entry_size); |
| 660 | |
| 661 | offset = entry->in_pack_offset; |
| 662 | if (offset_to_pack_pos(p, offset, &pos) < 0) |
| 663 | die(_("write_reuse_object: could not locate %s, expected at " |
| 664 | "offset %"PRIuMAX" in pack %s"), |
| 665 | oid_to_hex(&entry->idx.oid), (uintmax_t)offset, |
| 666 | p->pack_name); |
| 667 | datalen = pack_pos_to_offset(p, pos + 1) - offset; |
| 668 | if (!pack_to_stdout && p->index_version > 1 && |
| 669 | check_pack_crc(p, &w_curs, offset, datalen, |
| 670 | pack_pos_to_index(p, pos))) { |
| 671 | error(_("bad packed object CRC for %s"), |
| 672 | oid_to_hex(&entry->idx.oid)); |
| 673 | unuse_pack(&w_curs); |
| 674 | return write_no_reuse_object(f, entry, limit, usable_delta); |
| 675 | } |
| 676 | |
| 677 | offset += entry->in_pack_header_size; |
| 678 | datalen -= entry->in_pack_header_size; |
| 679 | |
| 680 | if (!pack_to_stdout && p->index_version == 1 && |
| 681 | check_pack_inflate(p, &w_curs, offset, datalen, entry_size)) { |
| 682 | error(_("corrupt packed object for %s"), |
| 683 | oid_to_hex(&entry->idx.oid)); |
| 684 | unuse_pack(&w_curs); |
| 685 | return write_no_reuse_object(f, entry, limit, usable_delta); |
| 686 | } |
| 687 | |
| 688 | if (type == OBJ_OFS_DELTA) { |
| 689 | off_t ofs = entry->idx.offset - DELTA(entry)->idx.offset; |
| 690 | unsigned pos = sizeof(dheader) - 1; |
no test coverage detected