* The per-object header is a pretty dense thing, which is * - first byte: low four bits are "size", then three bits of "type", * and the high bit is "size continues". * - each byte afterwards: low seven bits are size continuation, * with the high bit being "size continues" */
| 505 | * with the high bit being "size continues" |
| 506 | */ |
| 507 | int encode_in_pack_object_header(unsigned char *hdr, int hdr_len, |
| 508 | enum object_type type, uintmax_t size) |
| 509 | { |
| 510 | int n = 1; |
| 511 | unsigned char c; |
| 512 | |
| 513 | if (type < OBJ_COMMIT || type > OBJ_REF_DELTA) |
| 514 | die("bad type %d", type); |
| 515 | |
| 516 | c = (type << 4) | (size & 15); |
| 517 | size >>= 4; |
| 518 | while (size) { |
| 519 | if (n == hdr_len) |
| 520 | die("object size is too enormous to format"); |
| 521 | *hdr++ = c | 0x80; |
| 522 | c = size & 0x7f; |
| 523 | size >>= 7; |
| 524 | n++; |
| 525 | } |
| 526 | *hdr = c; |
| 527 | return n; |
| 528 | } |
| 529 | |
| 530 | struct hashfile *create_tmp_packfile(struct repository *repo, |
| 531 | char **pack_tmp_name) |