Return 0 if we will bust the pack-size limit */
| 723 | |
| 724 | /* Return 0 if we will bust the pack-size limit */ |
| 725 | static off_t write_object(struct hashfile *f, |
| 726 | struct object_entry *entry, |
| 727 | off_t write_offset) |
| 728 | { |
| 729 | unsigned long limit; |
| 730 | off_t len; |
| 731 | int usable_delta, to_reuse; |
| 732 | |
| 733 | if (!pack_to_stdout) |
| 734 | crc32_begin(f); |
| 735 | |
| 736 | /* apply size limit if limited packsize and not first object */ |
| 737 | if (!pack_size_limit || !nr_written) |
| 738 | limit = 0; |
| 739 | else if (pack_size_limit <= write_offset) |
| 740 | /* |
| 741 | * the earlier object did not fit the limit; avoid |
| 742 | * mistaking this with unlimited (i.e. limit = 0). |
| 743 | */ |
| 744 | limit = 1; |
| 745 | else |
| 746 | limit = pack_size_limit - write_offset; |
| 747 | |
| 748 | if (!DELTA(entry)) |
| 749 | usable_delta = 0; /* no delta */ |
| 750 | else if (!pack_size_limit) |
| 751 | usable_delta = 1; /* unlimited packfile */ |
| 752 | else if (DELTA(entry)->idx.offset == (off_t)-1) |
| 753 | usable_delta = 0; /* base was written to another pack */ |
| 754 | else if (DELTA(entry)->idx.offset) |
| 755 | usable_delta = 1; /* base already exists in this pack */ |
| 756 | else |
| 757 | usable_delta = 0; /* base could end up in another pack */ |
| 758 | |
| 759 | if (!reuse_object) |
| 760 | to_reuse = 0; /* explicit */ |
| 761 | else if (!IN_PACK(entry)) |
| 762 | to_reuse = 0; /* can't reuse what we don't have */ |
| 763 | else if (oe_type(entry) == OBJ_REF_DELTA || |
| 764 | oe_type(entry) == OBJ_OFS_DELTA) |
| 765 | /* check_object() decided it for us ... */ |
| 766 | to_reuse = usable_delta; |
| 767 | /* ... but pack split may override that */ |
| 768 | else if (oe_type(entry) != entry->in_pack_type) |
| 769 | to_reuse = 0; /* pack has delta which is unusable */ |
| 770 | else if (DELTA(entry)) |
| 771 | to_reuse = 0; /* we want to pack afresh */ |
| 772 | else |
| 773 | to_reuse = 1; /* we have it in-pack undeltified, |
| 774 | * and we do not need to deltify it. |
| 775 | */ |
| 776 | |
| 777 | if (!to_reuse) |
| 778 | len = write_no_reuse_object(f, entry, limit, usable_delta); |
| 779 | else |
| 780 | len = write_reuse_object(f, entry, limit, usable_delta); |
| 781 | if (!len) |
| 782 | return 0; |
no test coverage detected