diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2013-10-03 18:54:25 +0400 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2013-10-04 12:18:20 +0400 |
commit | 51e82492ef5206767e176952733914275d0e3bdc (patch) | |
tree | 44ed00901ac72d8cb9d92dc27d90b06f576b55a6 /src/pack.c | |
parent | cf0582b43ce591e7923637d2c8925028aaa5977b (diff) |
pack: move the object header function here
Diffstat (limited to 'src/pack.c')
-rw-r--r-- | src/pack.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/pack.c b/src/pack.c index e7fb9f1ae..5df0f50b9 100644 --- a/src/pack.c +++ b/src/pack.c @@ -364,6 +364,38 @@ static unsigned char *pack_window_open( return git_mwindow_open(&p->mwf, w_cursor, offset, 20, left); } +/* + * The per-object header is a pretty dense thing, which is + * - first byte: low four bits are "size", + * then three bits of "type", + * with the high bit being "size continues". + * - each byte afterwards: low seven bits are size continuation, + * with the high bit being "size continues" + */ +int git_packfile__object_header(unsigned char *hdr, unsigned long size, git_otype type) +{ + unsigned char *hdr_base; + unsigned char c; + + assert(type >= GIT_OBJ_COMMIT && type <= GIT_OBJ_REF_DELTA); + + /* TODO: add support for chunked objects; see git.git 6c0d19b1 */ + + c = (unsigned char)((type << 4) | (size & 15)); + size >>= 4; + hdr_base = hdr; + + while (size) { + *hdr++ = c | 0x80; + c = size & 0x7f; + size >>= 7; + } + *hdr++ = c; + + return (int)(hdr - hdr_base); +} + + static int packfile_unpack_header1( unsigned long *usedp, size_t *sizep, |