move encode_in_pack_object_header() to a better place
Commit 1b22b6c897
made duplicated versions of encode_header() into a
common version called encode_in_pack_object_header(). There is however
a better location that sha1_file.c for such a function though, as
sha1_file.c contains nothing related to the creation of packs, and
it is quite populated already.
Also the comment that was moved to the header file should really remain
near the function as it covers implementation details and provides no
information about the actual function interface.
Signed-off-by: Nicolas Pitre <nico@fluxnic.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
1b22b6c897
commit
f965c525a4
27
pack-write.c
27
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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user