uint32_t nr_written;
};
-struct odb_transaction {
- struct odb_source *source;
+struct odb_transaction_files {
+ struct odb_transaction base;
struct tmp_objdir *objdir;
struct transaction_packfile packfile;
};
-static void prepare_loose_object_transaction(struct odb_transaction *transaction)
+static void prepare_loose_object_transaction(struct odb_transaction *base)
{
+ struct odb_transaction_files *transaction = (struct odb_transaction_files *)base;
+
/*
* We lazily create the temporary object directory
* the first time an object might be added, since
if (!transaction || transaction->objdir)
return;
- transaction->objdir = tmp_objdir_create(transaction->source->odb->repo, "bulk-fsync");
+ transaction->objdir = tmp_objdir_create(base->source->odb->repo, "bulk-fsync");
if (transaction->objdir)
tmp_objdir_replace_primary_odb(transaction->objdir, 0);
}
-static void fsync_loose_object_transaction(struct odb_transaction *transaction,
+static void fsync_loose_object_transaction(struct odb_transaction *base,
int fd, const char *filename)
{
+ struct odb_transaction_files *transaction = (struct odb_transaction_files *)base;
+
/*
* If we have an active ODB transaction, we issue a call that
* cleans the filesystem page cache but avoids a hardware flush
/*
* Cleanup after batch-mode fsync_object_files.
*/
-static void flush_loose_object_transaction(struct odb_transaction *transaction)
+static void flush_loose_object_transaction(struct odb_transaction_files *transaction)
{
struct strbuf temp_path = STRBUF_INIT;
struct tempfile *temp;
* the final name is visible.
*/
strbuf_addf(&temp_path, "%s/bulk_fsync_XXXXXX",
- repo_get_object_directory(transaction->source->odb->repo));
+ repo_get_object_directory(transaction->base.source->odb->repo));
temp = xmks_tempfile(temp_path.buf);
fsync_or_die(get_tempfile_fd(temp), get_tempfile_path(temp));
delete_tempfile(&temp);
return ret;
}
-static int already_written(struct odb_transaction *transaction,
+static int already_written(struct odb_transaction_files *transaction,
struct object_id *oid)
{
/* The object may already exist in the repository */
- if (odb_has_object(transaction->source->odb, oid,
+ if (odb_has_object(transaction->base.source->odb, oid,
HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
return 1;
}
/* Lazily create backing packfile for the state */
-static void prepare_packfile_transaction(struct odb_transaction *transaction,
+static void prepare_packfile_transaction(struct odb_transaction_files *transaction,
unsigned flags)
{
struct transaction_packfile *state = &transaction->packfile;
if (!(flags & INDEX_WRITE_OBJECT) || state->f)
return;
- state->f = create_tmp_packfile(transaction->source->odb->repo,
+ state->f = create_tmp_packfile(transaction->base.source->odb->repo,
&state->pack_tmp_name);
reset_pack_idx_option(&state->pack_idx_opts);
return 0;
}
-static void flush_packfile_transaction(struct odb_transaction *transaction)
+static void flush_packfile_transaction(struct odb_transaction_files *transaction)
{
struct transaction_packfile *state = &transaction->packfile;
- struct repository *repo = transaction->source->odb->repo;
+ struct repository *repo = transaction->base.source->odb->repo;
unsigned char hash[GIT_MAX_RAWSZ];
struct strbuf packname = STRBUF_INIT;
char *idx_tmp_name = NULL;
}
strbuf_addf(&packname, "%s/pack/pack-%s.",
- repo_get_object_directory(transaction->source->odb->repo),
+ repo_get_object_directory(transaction->base.source->odb->repo),
hash_to_hex_algop(hash, repo->hash_algo));
stage_tmp_packfiles(repo, &packname, state->pack_tmp_name,
* binary blobs, they generally do not want to get any conversion, and
* callers should avoid this code path when filters are requested.
*/
-static int index_blob_packfile_transaction(struct odb_transaction *transaction,
+static int index_blob_packfile_transaction(struct odb_transaction_files *transaction,
struct object_id *result_oid, int fd,
size_t size, const char *path,
unsigned flags)
header_len = format_object_header((char *)obuf, sizeof(obuf),
OBJ_BLOB, size);
- transaction->source->odb->repo->hash_algo->init_fn(&ctx);
+ transaction->base.source->odb->repo->hash_algo->init_fn(&ctx);
git_hash_update(&ctx, obuf, header_len);
/* Note: idx is non-NULL when we are writing */
ret = index_core(istate, oid, fd, xsize_t(st->st_size),
type, path, flags);
} else {
+ struct object_database *odb = the_repository->objects;
struct odb_transaction *transaction;
- transaction = odb_transaction_begin(the_repository->objects);
- ret = index_blob_packfile_transaction(the_repository->objects->transaction,
+ transaction = odb_transaction_begin(odb);
+ ret = index_blob_packfile_transaction((struct odb_transaction_files *)odb->transaction,
oid, fd,
xsize_t(st->st_size),
path, flags);
return ret;
}
-struct odb_transaction *odb_transaction_files_begin(struct odb_source *source)
+static void odb_transaction_files_commit(struct odb_transaction *base)
{
- struct object_database *odb = source->odb;
-
- if (odb->transaction)
- return NULL;
-
- CALLOC_ARRAY(odb->transaction, 1);
- odb->transaction->source = source;
-
- return odb->transaction;
-}
-
-void odb_transaction_files_commit(struct odb_transaction *transaction)
-{
- if (!transaction)
- return;
+ struct odb_transaction_files *transaction = (struct odb_transaction_files *)base;
/*
* Ensure the transaction ending matches the pending transaction.
*/
- ASSERT(transaction == transaction->source->odb->transaction);
+ ASSERT(base == base->source->odb->transaction);
flush_loose_object_transaction(transaction);
flush_packfile_transaction(transaction);
- transaction->source->odb->transaction = NULL;
+ base->source->odb->transaction = NULL;
free(transaction);
}
+struct odb_transaction *odb_transaction_files_begin(struct odb_source *source)
+{
+ struct odb_transaction_files *transaction;
+ struct object_database *odb = source->odb;
+
+ if (odb->transaction)
+ return NULL;
+
+ transaction = xcalloc(1, sizeof(*transaction));
+ transaction->base.source = source;
+ transaction->base.commit = odb_transaction_files_commit;
+
+ odb->transaction = &transaction->base;
+
+ return &transaction->base;
+}
+
struct odb_source_loose *odb_source_loose_new(struct odb_source *source)
{
struct odb_source_loose *loose;