diff options
author | Junio C Hamano <gitster@pobox.com> | 2010-03-02 12:44:11 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-03-02 12:44:11 -0800 |
commit | 77b30bcecd84225a21a8639c272fde88180f36d9 (patch) | |
tree | 0d2b1d071c37b119943a88c195ff2bfd50e3f500 /pack-write.c | |
parent | Merge branch 'jn/gitweb-config-error-die' (diff) | |
parent | move encode_in_pack_object_header() to a better place (diff) | |
download | tgif-77b30bcecd84225a21a8639c272fde88180f36d9.tar.xz |
Merge branch 'ml/encode-header-refactor'
* ml/encode-header-refactor:
move encode_in_pack_object_header() to a better place
refactor duplicated encode_header in pack-objects and fast-import
Diffstat (limited to 'pack-write.c')
-rw-r--r-- | pack-write.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/pack-write.c b/pack-write.c index 9f47cf9961..a905ca4486 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; +} |