diff options
Diffstat (limited to 'bulk-checkin.c')
-rw-r--r-- | bulk-checkin.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/bulk-checkin.c b/bulk-checkin.c index 118c62528b..991b4a13e2 100644 --- a/bulk-checkin.c +++ b/bulk-checkin.c @@ -1,11 +1,11 @@ /* * Copyright (c) 2011, Google Inc. */ +#include "cache.h" #include "bulk-checkin.h" #include "csum-file.h" #include "pack.h" - -static int pack_compression_level = Z_DEFAULT_COMPRESSION; +#include "strbuf.h" static struct bulk_checkin_state { unsigned plugged:1; @@ -22,8 +22,8 @@ static struct bulk_checkin_state { static void finish_bulk_checkin(struct bulk_checkin_state *state) { - unsigned char sha1[20]; - char packname[PATH_MAX]; + struct object_id oid; + struct strbuf packname = STRBUF_INIT; int i; if (!state->f) @@ -34,19 +34,19 @@ static void finish_bulk_checkin(struct bulk_checkin_state *state) unlink(state->pack_tmp_name); goto clear_exit; } else if (state->nr_written == 1) { - sha1close(state->f, sha1, CSUM_FSYNC); + sha1close(state->f, oid.hash, CSUM_FSYNC); } else { - int fd = sha1close(state->f, sha1, 0); - fixup_pack_header_footer(fd, sha1, state->pack_tmp_name, - state->nr_written, sha1, + int fd = sha1close(state->f, oid.hash, 0); + fixup_pack_header_footer(fd, oid.hash, state->pack_tmp_name, + state->nr_written, oid.hash, state->offset); close(fd); } - sprintf(packname, "%s/pack/pack-", get_object_directory()); - finish_tmp_packfile(packname, state->pack_tmp_name, + strbuf_addf(&packname, "%s/pack/pack-", get_object_directory()); + finish_tmp_packfile(&packname, state->pack_tmp_name, state->written, state->nr_written, - &state->pack_idx_opts, sha1); + &state->pack_idx_opts, oid.hash); for (i = 0; i < state->nr_written; i++) free(state->written[i]); @@ -54,6 +54,7 @@ clear_exit: free(state->written); memset(state, 0, sizeof(*state)); + strbuf_release(&packname); /* Make objects we just wrote available to ourselves */ reprepare_packed_git(); } @@ -102,7 +103,6 @@ static int stream_to_pack(struct bulk_checkin_state *state, int write_object = (flags & HASH_WRITE_OBJECT); off_t offset = 0; - memset(&s, 0, sizeof(s)); git_deflate_init(&s, pack_compression_level); hdrlen = encode_in_pack_object_header(type, size, obuf); @@ -198,8 +198,8 @@ static int deflate_to_pack(struct bulk_checkin_state *state, if (seekback == (off_t) -1) return error("cannot find the current offset"); - header_len = sprintf((char *)obuf, "%s %" PRIuMAX, - typename(type), (uintmax_t)size) + 1; + header_len = xsnprintf((char *)obuf, sizeof(obuf), "%s %" PRIuMAX, + typename(type), (uintmax_t)size) + 1; git_SHA1_Init(&ctx); git_SHA1_Update(&ctx, obuf, header_len); |