die_errno("unable to write pack header");
}
-static int deflate_blob_to_pack(struct bulk_checkin_packfile *state,
- struct object_id *result_oid,
- int fd, size_t size,
- const char *path, unsigned flags)
+int index_blob_bulk_checkin(struct odb_transaction *transaction,
+ struct object_id *result_oid, int fd, size_t size,
+ const char *path, unsigned flags)
{
+ struct bulk_checkin_packfile *state = &transaction->packfile;
off_t seekback, already_hashed_to;
struct git_hash_ctx ctx;
unsigned char obuf[16384];
}
}
-int index_blob_bulk_checkin(struct odb_transaction *transaction,
- struct object_id *oid, int fd, size_t size,
- const char *path, unsigned flags)
-{
- int status;
-
- if (transaction) {
- status = deflate_blob_to_pack(&transaction->packfile, oid, fd,
- size, path, flags);
- } else {
- struct bulk_checkin_packfile state = { 0 };
-
- status = deflate_blob_to_pack(&state, oid, fd, size, path, flags);
- flush_bulk_checkin_packfile(&state);
- }
-
- return status;
-}
-
struct odb_transaction *begin_odb_transaction(struct object_database *odb)
{
if (!odb->transaction) {
int fd, const char *filename);
/*
- * This creates one packfile per large blob unless bulk-checkin
- * machinery is "plugged".
+ * This writes the specified object to a packfile. Objects written here
+ * during the same transaction are written to the same packfile. The
+ * packfile is not flushed until the transaction is flushed. The caller
+ * is expected to ensure a valid transaction is setup for objects to be
+ * recorded to.
*
* This also bypasses the usual "convert-to-git" dance, and that is on
* purpose. We could write a streaming version of the converting
* Call xsize_t() only when needed to avoid potentially unnecessary
* die() for large files.
*/
- if (type == OBJ_BLOB && path && would_convert_to_git_filter_fd(istate, path))
+ if (type == OBJ_BLOB && path && would_convert_to_git_filter_fd(istate, path)) {
ret = index_stream_convert_blob(istate, oid, fd, path, flags);
- else if (!S_ISREG(st->st_mode))
+ } else if (!S_ISREG(st->st_mode)) {
ret = index_pipe(istate, oid, fd, type, path, flags);
- else if ((st->st_size >= 0 && (size_t) st->st_size <= repo_settings_get_big_file_threshold(istate->repo)) ||
- type != OBJ_BLOB ||
- (path && would_convert_to_git(istate, path)))
+ } else if ((st->st_size >= 0 &&
+ (size_t)st->st_size <= repo_settings_get_big_file_threshold(istate->repo)) ||
+ type != OBJ_BLOB ||
+ (path && would_convert_to_git(istate, path))) {
ret = index_core(istate, oid, fd, xsize_t(st->st_size),
type, path, flags);
- else
- ret = index_blob_bulk_checkin(the_repository->objects->transaction,
+ } else {
+ struct odb_transaction *transaction;
+
+ transaction = begin_odb_transaction(the_repository->objects);
+ ret = index_blob_bulk_checkin(transaction,
oid, fd, xsize_t(st->st_size),
path, flags);
+ end_odb_transaction(transaction);
+ }
+
close(fd);
return ret;
}