bulk-checkin: use repository variable from transaction
The bulk-checkin subsystem depends on `the_repository`. Adapt functions and call sites to access the repository through `struct odb_transaction` instead. The `USE_THE_REPOSITORY_VARIBALE` is still required as the `pack_compression_level` and `pack_size_limit_cfg` globals are still used. Also adapt functions using packfile state to instead access it through the transaction. This makes some function parameters redundant and go away. Signed-off-by: Justin Tobler <jltobler@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>main
parent
aa4d81b533
commit
ddc0b56ad7
|
@ -38,25 +38,26 @@ struct odb_transaction {
|
||||||
struct bulk_checkin_packfile packfile;
|
struct bulk_checkin_packfile packfile;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void finish_tmp_packfile(struct strbuf *basename,
|
static void finish_tmp_packfile(struct odb_transaction *transaction,
|
||||||
const char *pack_tmp_name,
|
struct strbuf *basename,
|
||||||
struct pack_idx_entry **written_list,
|
|
||||||
uint32_t nr_written,
|
|
||||||
struct pack_idx_option *pack_idx_opts,
|
|
||||||
unsigned char hash[])
|
unsigned char hash[])
|
||||||
{
|
{
|
||||||
|
struct bulk_checkin_packfile *state = &transaction->packfile;
|
||||||
|
struct repository *repo = transaction->odb->repo;
|
||||||
char *idx_tmp_name = NULL;
|
char *idx_tmp_name = NULL;
|
||||||
|
|
||||||
stage_tmp_packfiles(the_repository, basename, pack_tmp_name,
|
stage_tmp_packfiles(repo, basename, state->pack_tmp_name,
|
||||||
written_list, nr_written, NULL, pack_idx_opts, hash,
|
state->written, state->nr_written, NULL,
|
||||||
&idx_tmp_name);
|
&state->pack_idx_opts, hash, &idx_tmp_name);
|
||||||
rename_tmp_packfile_idx(the_repository, basename, &idx_tmp_name);
|
rename_tmp_packfile_idx(repo, basename, &idx_tmp_name);
|
||||||
|
|
||||||
free(idx_tmp_name);
|
free(idx_tmp_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void flush_bulk_checkin_packfile(struct bulk_checkin_packfile *state)
|
static void flush_bulk_checkin_packfile(struct odb_transaction *transaction)
|
||||||
{
|
{
|
||||||
|
struct bulk_checkin_packfile *state = &transaction->packfile;
|
||||||
|
struct repository *repo = transaction->odb->repo;
|
||||||
unsigned char hash[GIT_MAX_RAWSZ];
|
unsigned char hash[GIT_MAX_RAWSZ];
|
||||||
struct strbuf packname = STRBUF_INIT;
|
struct strbuf packname = STRBUF_INIT;
|
||||||
|
|
||||||
|
@ -73,17 +74,17 @@ static void flush_bulk_checkin_packfile(struct bulk_checkin_packfile *state)
|
||||||
CSUM_HASH_IN_STREAM | CSUM_FSYNC | CSUM_CLOSE);
|
CSUM_HASH_IN_STREAM | CSUM_FSYNC | CSUM_CLOSE);
|
||||||
} else {
|
} else {
|
||||||
int fd = finalize_hashfile(state->f, hash, FSYNC_COMPONENT_PACK, 0);
|
int fd = finalize_hashfile(state->f, hash, FSYNC_COMPONENT_PACK, 0);
|
||||||
fixup_pack_header_footer(the_hash_algo, fd, hash, state->pack_tmp_name,
|
fixup_pack_header_footer(repo->hash_algo, fd, hash, state->pack_tmp_name,
|
||||||
state->nr_written, hash,
|
state->nr_written, hash,
|
||||||
state->offset);
|
state->offset);
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
strbuf_addf(&packname, "%s/pack/pack-%s.", repo_get_object_directory(the_repository),
|
strbuf_addf(&packname, "%s/pack/pack-%s.",
|
||||||
hash_to_hex(hash));
|
repo_get_object_directory(transaction->odb->repo),
|
||||||
finish_tmp_packfile(&packname, state->pack_tmp_name,
|
hash_to_hex_algop(hash, repo->hash_algo));
|
||||||
state->written, state->nr_written,
|
|
||||||
&state->pack_idx_opts, hash);
|
finish_tmp_packfile(transaction, &packname, hash);
|
||||||
for (uint32_t i = 0; i < state->nr_written; i++)
|
for (uint32_t i = 0; i < state->nr_written; i++)
|
||||||
free(state->written[i]);
|
free(state->written[i]);
|
||||||
|
|
||||||
|
@ -94,7 +95,7 @@ clear_exit:
|
||||||
|
|
||||||
strbuf_release(&packname);
|
strbuf_release(&packname);
|
||||||
/* Make objects we just wrote available to ourselves */
|
/* Make objects we just wrote available to ourselves */
|
||||||
reprepare_packed_git(the_repository);
|
reprepare_packed_git(repo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -117,7 +118,8 @@ static void flush_batch_fsync(struct odb_transaction *transaction)
|
||||||
* to ensure that the data in each new object file is durable before
|
* to ensure that the data in each new object file is durable before
|
||||||
* the final name is visible.
|
* the final name is visible.
|
||||||
*/
|
*/
|
||||||
strbuf_addf(&temp_path, "%s/bulk_fsync_XXXXXX", repo_get_object_directory(the_repository));
|
strbuf_addf(&temp_path, "%s/bulk_fsync_XXXXXX",
|
||||||
|
repo_get_object_directory(transaction->odb->repo));
|
||||||
temp = xmks_tempfile(temp_path.buf);
|
temp = xmks_tempfile(temp_path.buf);
|
||||||
fsync_or_die(get_tempfile_fd(temp), get_tempfile_path(temp));
|
fsync_or_die(get_tempfile_fd(temp), get_tempfile_path(temp));
|
||||||
delete_tempfile(&temp);
|
delete_tempfile(&temp);
|
||||||
|
@ -131,16 +133,17 @@ static void flush_batch_fsync(struct odb_transaction *transaction)
|
||||||
transaction->objdir = NULL;
|
transaction->objdir = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int already_written(struct bulk_checkin_packfile *state, struct object_id *oid)
|
static int already_written(struct odb_transaction *transaction,
|
||||||
|
struct object_id *oid)
|
||||||
{
|
{
|
||||||
/* The object may already exist in the repository */
|
/* The object may already exist in the repository */
|
||||||
if (odb_has_object(the_repository->objects, oid,
|
if (odb_has_object(transaction->odb, oid,
|
||||||
HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
|
HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
/* Might want to keep the list sorted */
|
/* Might want to keep the list sorted */
|
||||||
for (uint32_t i = 0; i < state->nr_written; i++)
|
for (uint32_t i = 0; i < transaction->packfile.nr_written; i++)
|
||||||
if (oideq(&state->written[i]->oid, oid))
|
if (oideq(&transaction->packfile.written[i]->oid, oid))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
/* This is a new object we need to keep */
|
/* This is a new object we need to keep */
|
||||||
|
@ -239,13 +242,15 @@ static int stream_blob_to_pack(struct bulk_checkin_packfile *state,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Lazily create backing packfile for the state */
|
/* Lazily create backing packfile for the state */
|
||||||
static void prepare_to_stream(struct bulk_checkin_packfile *state,
|
static void prepare_to_stream(struct odb_transaction *transaction,
|
||||||
unsigned flags)
|
unsigned flags)
|
||||||
{
|
{
|
||||||
|
struct bulk_checkin_packfile *state = &transaction->packfile;
|
||||||
if (!(flags & INDEX_WRITE_OBJECT) || state->f)
|
if (!(flags & INDEX_WRITE_OBJECT) || state->f)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
state->f = create_tmp_packfile(the_repository, &state->pack_tmp_name);
|
state->f = create_tmp_packfile(transaction->odb->repo,
|
||||||
|
&state->pack_tmp_name);
|
||||||
reset_pack_idx_option(&state->pack_idx_opts);
|
reset_pack_idx_option(&state->pack_idx_opts);
|
||||||
|
|
||||||
/* Pretend we are going to write only one object */
|
/* Pretend we are going to write only one object */
|
||||||
|
@ -272,21 +277,21 @@ int index_blob_bulk_checkin(struct odb_transaction *transaction,
|
||||||
|
|
||||||
header_len = format_object_header((char *)obuf, sizeof(obuf),
|
header_len = format_object_header((char *)obuf, sizeof(obuf),
|
||||||
OBJ_BLOB, size);
|
OBJ_BLOB, size);
|
||||||
the_hash_algo->init_fn(&ctx);
|
transaction->odb->repo->hash_algo->init_fn(&ctx);
|
||||||
git_hash_update(&ctx, obuf, header_len);
|
git_hash_update(&ctx, obuf, header_len);
|
||||||
|
|
||||||
/* Note: idx is non-NULL when we are writing */
|
/* Note: idx is non-NULL when we are writing */
|
||||||
if ((flags & INDEX_WRITE_OBJECT) != 0) {
|
if ((flags & INDEX_WRITE_OBJECT) != 0) {
|
||||||
CALLOC_ARRAY(idx, 1);
|
CALLOC_ARRAY(idx, 1);
|
||||||
|
|
||||||
prepare_to_stream(state, flags);
|
prepare_to_stream(transaction, flags);
|
||||||
hashfile_checkpoint_init(state->f, &checkpoint);
|
hashfile_checkpoint_init(state->f, &checkpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
already_hashed_to = 0;
|
already_hashed_to = 0;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
prepare_to_stream(state, flags);
|
prepare_to_stream(transaction, flags);
|
||||||
if (idx) {
|
if (idx) {
|
||||||
hashfile_checkpoint(state->f, &checkpoint);
|
hashfile_checkpoint(state->f, &checkpoint);
|
||||||
idx->offset = state->offset;
|
idx->offset = state->offset;
|
||||||
|
@ -304,7 +309,7 @@ int index_blob_bulk_checkin(struct odb_transaction *transaction,
|
||||||
BUG("should not happen");
|
BUG("should not happen");
|
||||||
hashfile_truncate(state->f, &checkpoint);
|
hashfile_truncate(state->f, &checkpoint);
|
||||||
state->offset = checkpoint.offset;
|
state->offset = checkpoint.offset;
|
||||||
flush_bulk_checkin_packfile(state);
|
flush_bulk_checkin_packfile(transaction);
|
||||||
if (lseek(fd, seekback, SEEK_SET) == (off_t) -1)
|
if (lseek(fd, seekback, SEEK_SET) == (off_t) -1)
|
||||||
return error("cannot seek back");
|
return error("cannot seek back");
|
||||||
}
|
}
|
||||||
|
@ -313,7 +318,7 @@ int index_blob_bulk_checkin(struct odb_transaction *transaction,
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
idx->crc32 = crc32_end(state->f);
|
idx->crc32 = crc32_end(state->f);
|
||||||
if (already_written(state, result_oid)) {
|
if (already_written(transaction, result_oid)) {
|
||||||
hashfile_truncate(state->f, &checkpoint);
|
hashfile_truncate(state->f, &checkpoint);
|
||||||
state->offset = checkpoint.offset;
|
state->offset = checkpoint.offset;
|
||||||
free(idx);
|
free(idx);
|
||||||
|
@ -338,7 +343,7 @@ void prepare_loose_object_bulk_checkin(struct odb_transaction *transaction)
|
||||||
if (!transaction || transaction->objdir)
|
if (!transaction || transaction->objdir)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
transaction->objdir = tmp_objdir_create(the_repository, "bulk-fsync");
|
transaction->objdir = tmp_objdir_create(transaction->odb->repo, "bulk-fsync");
|
||||||
if (transaction->objdir)
|
if (transaction->objdir)
|
||||||
tmp_objdir_replace_primary_odb(transaction->objdir, 0);
|
tmp_objdir_replace_primary_odb(transaction->objdir, 0);
|
||||||
}
|
}
|
||||||
|
@ -379,7 +384,7 @@ void flush_odb_transaction(struct odb_transaction *transaction)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
flush_batch_fsync(transaction);
|
flush_batch_fsync(transaction);
|
||||||
flush_bulk_checkin_packfile(&transaction->packfile);
|
flush_bulk_checkin_packfile(transaction);
|
||||||
}
|
}
|
||||||
|
|
||||||
void end_odb_transaction(struct odb_transaction *transaction)
|
void end_odb_transaction(struct odb_transaction *transaction)
|
||||||
|
|
Loading…
Reference in New Issue