aboutsummaryrefslogtreecommitdiffstats
path: root/bulk-checkin.c
diff options
context:
space:
mode:
Diffstat (limited to 'bulk-checkin.c')
-rw-r--r--bulk-checkin.c54
1 files changed, 28 insertions, 26 deletions
diff --git a/bulk-checkin.c b/bulk-checkin.c
index 2753d5bbe4..16df86c0ba 100644
--- a/bulk-checkin.c
+++ b/bulk-checkin.c
@@ -17,7 +17,7 @@
#include "tmp-objdir.h"
#include "packfile.h"
#include "object-file.h"
-#include "object-store-ll.h"
+#include "odb.h"
static int odb_transaction_nesting;
@@ -43,8 +43,9 @@ static void finish_tmp_packfile(struct strbuf *basename,
{
char *idx_tmp_name = NULL;
- stage_tmp_packfiles(basename, pack_tmp_name, written_list, nr_written,
- NULL, pack_idx_opts, hash, &idx_tmp_name);
+ stage_tmp_packfiles(the_repository, basename, pack_tmp_name,
+ written_list, nr_written, NULL, pack_idx_opts, hash,
+ &idx_tmp_name);
rename_tmp_packfile_idx(basename, &idx_tmp_name);
free(idx_tmp_name);
@@ -54,7 +55,6 @@ static void flush_bulk_checkin_packfile(struct bulk_checkin_packfile *state)
{
unsigned char hash[GIT_MAX_RAWSZ];
struct strbuf packname = STRBUF_INIT;
- int i;
if (!state->f)
return;
@@ -69,7 +69,7 @@ static void flush_bulk_checkin_packfile(struct bulk_checkin_packfile *state)
CSUM_HASH_IN_STREAM | CSUM_FSYNC | CSUM_CLOSE);
} else {
int fd = finalize_hashfile(state->f, hash, FSYNC_COMPONENT_PACK, 0);
- fixup_pack_header_footer(fd, hash, state->pack_tmp_name,
+ fixup_pack_header_footer(the_hash_algo, fd, hash, state->pack_tmp_name,
state->nr_written, hash,
state->offset);
close(fd);
@@ -80,7 +80,7 @@ static void flush_bulk_checkin_packfile(struct bulk_checkin_packfile *state)
finish_tmp_packfile(&packname, state->pack_tmp_name,
state->written, state->nr_written,
&state->pack_idx_opts, hash);
- for (i = 0; i < state->nr_written; i++)
+ for (uint32_t i = 0; i < state->nr_written; i++)
free(state->written[i]);
clear_exit:
@@ -129,14 +129,13 @@ static void flush_batch_fsync(void)
static int already_written(struct bulk_checkin_packfile *state, struct object_id *oid)
{
- int i;
-
/* The object may already exist in the repository */
- if (repo_has_object_file(the_repository, oid))
+ if (odb_has_object(the_repository->objects, oid,
+ HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return 1;
/* Might want to keep the list sorted */
- for (i = 0; i < state->nr_written; i++)
+ for (uint32_t i = 0; i < state->nr_written; i++)
if (oideq(&state->written[i]->oid, oid))
return 1;
@@ -160,7 +159,7 @@ static int already_written(struct bulk_checkin_packfile *state, struct object_id
* with a new pack.
*/
static int stream_blob_to_pack(struct bulk_checkin_packfile *state,
- git_hash_ctx *ctx, off_t *already_hashed_to,
+ struct git_hash_ctx *ctx, off_t *already_hashed_to,
int fd, size_t size, const char *path,
unsigned flags)
{
@@ -169,7 +168,7 @@ static int stream_blob_to_pack(struct bulk_checkin_packfile *state,
unsigned char obuf[16384];
unsigned hdrlen;
int status = Z_OK;
- int write_object = (flags & HASH_WRITE_OBJECT);
+ int write_object = (flags & INDEX_WRITE_OBJECT);
off_t offset = 0;
git_deflate_init(&s, pack_compression_level);
@@ -180,20 +179,20 @@ static int stream_blob_to_pack(struct bulk_checkin_packfile *state,
while (status != Z_STREAM_END) {
if (size && !s.avail_in) {
- ssize_t rsize = size < sizeof(ibuf) ? size : sizeof(ibuf);
+ size_t rsize = size < sizeof(ibuf) ? size : sizeof(ibuf);
ssize_t read_result = read_in_full(fd, ibuf, rsize);
if (read_result < 0)
die_errno("failed to read from '%s'", path);
- if (read_result != rsize)
- die("failed to read %d bytes from '%s'",
- (int)rsize, path);
+ if ((size_t)read_result != rsize)
+ die("failed to read %u bytes from '%s'",
+ (unsigned)rsize, path);
offset += rsize;
if (*already_hashed_to < offset) {
size_t hsize = offset - *already_hashed_to;
if (rsize < hsize)
hsize = rsize;
if (hsize)
- the_hash_algo->update_fn(ctx, ibuf, hsize);
+ git_hash_update(ctx, ibuf, hsize);
*already_hashed_to = offset;
}
s.next_in = ibuf;
@@ -239,10 +238,10 @@ static int stream_blob_to_pack(struct bulk_checkin_packfile *state,
static void prepare_to_stream(struct bulk_checkin_packfile *state,
unsigned flags)
{
- if (!(flags & HASH_WRITE_OBJECT) || state->f)
+ if (!(flags & INDEX_WRITE_OBJECT) || state->f)
return;
- state->f = create_tmp_packfile(&state->pack_tmp_name);
+ state->f = create_tmp_packfile(the_repository, &state->pack_tmp_name);
reset_pack_idx_option(&state->pack_idx_opts);
/* Pretend we are going to write only one object */
@@ -257,10 +256,10 @@ static int deflate_blob_to_pack(struct bulk_checkin_packfile *state,
const char *path, unsigned flags)
{
off_t seekback, already_hashed_to;
- git_hash_ctx ctx;
+ struct git_hash_ctx ctx;
unsigned char obuf[16384];
unsigned header_len;
- struct hashfile_checkpoint checkpoint = {0};
+ struct hashfile_checkpoint checkpoint;
struct pack_idx_entry *idx = NULL;
seekback = lseek(fd, 0, SEEK_CUR);
@@ -270,13 +269,16 @@ static int deflate_blob_to_pack(struct bulk_checkin_packfile *state,
header_len = format_object_header((char *)obuf, sizeof(obuf),
OBJ_BLOB, size);
the_hash_algo->init_fn(&ctx);
- the_hash_algo->update_fn(&ctx, obuf, header_len);
- the_hash_algo->init_fn(&checkpoint.ctx);
+ git_hash_update(&ctx, obuf, header_len);
/* Note: idx is non-NULL when we are writing */
- if ((flags & HASH_WRITE_OBJECT) != 0)
+ if ((flags & INDEX_WRITE_OBJECT) != 0) {
CALLOC_ARRAY(idx, 1);
+ prepare_to_stream(state, flags);
+ hashfile_checkpoint_init(state->f, &checkpoint);
+ }
+
already_hashed_to = 0;
while (1) {
@@ -302,7 +304,7 @@ static int deflate_blob_to_pack(struct bulk_checkin_packfile *state,
if (lseek(fd, seekback, SEEK_SET) == (off_t) -1)
return error("cannot seek back");
}
- the_hash_algo->final_oid_fn(result_oid, &ctx);
+ git_hash_final_oid(result_oid, &ctx);
if (!idx)
return 0;
@@ -332,7 +334,7 @@ void prepare_loose_object_bulk_checkin(void)
if (!odb_transaction_nesting || bulk_fsync_objdir)
return;
- bulk_fsync_objdir = tmp_objdir_create("bulk-fsync");
+ bulk_fsync_objdir = tmp_objdir_create(the_repository, "bulk-fsync");
if (bulk_fsync_objdir)
tmp_objdir_replace_primary_odb(bulk_fsync_objdir, 0);
}