X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=pack-write.c;h=a905ca4486754f099a30f90a2fcd22d0c771a070;hb=d577cd216e0adb9cbc726dddd1a0858b4ab4e6e3;hp=9f47cf9961212242bc01082944e83fb54da2a515;hpb=8165952517bf82b6a632cefc047ad14f36a74b25;p=git.git diff --git a/pack-write.c b/pack-write.c index 9f47cf996..a905ca448 100644 --- a/pack-write.c +++ b/pack-write.c @@ -253,3 +253,30 @@ char *index_pack_lockfile(int ip_out) } return NULL; } + +/* + * 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" + */ +int encode_in_pack_object_header(enum object_type type, uintmax_t size, unsigned char *hdr) +{ + int n = 1; + unsigned char c; + + if (type < OBJ_COMMIT || type > OBJ_REF_DELTA) + die("bad type %d", type); + + c = (type << 4) | (size & 15); + size >>= 4; + while (size) { + *hdr++ = c | 0x80; + c = size & 0x7f; + size >>= 7; + n++; + } + *hdr = c; + return n; +}