From c0ad465725302b9411e53d248871c36880b6f8fd Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 28 Oct 2011 11:40:48 -0700 Subject: write_pack_header(): a helper function Factor out a small logic out of the private write_pack_file() function in builtin/pack-objects.c Signed-off-by: Junio C Hamano --- pack-write.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'pack-write.c') diff --git a/pack-write.c b/pack-write.c index 9cd3bfbb4..46f3f846b 100644 --- a/pack-write.c +++ b/pack-write.c @@ -178,6 +178,18 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec return index_name; } +off_t write_pack_header(struct sha1file *f, uint32_t nr_entries) +{ + struct pack_header hdr; + + hdr.hdr_signature = htonl(PACK_SIGNATURE); + hdr.hdr_version = htonl(PACK_VERSION); + hdr.hdr_entries = htonl(nr_entries); + if (sha1write(f, &hdr, sizeof(hdr))) + return 0; + return sizeof(hdr); +} + /* * Update pack header with object_count and compute new SHA1 for pack data * associated to pack_fd, and write that SHA1 at the end. That new SHA1 -- cgit v1.2.1