object-file: update naming from bulk-checkin

Update the names of several functions and types relocated from the bulk-checkin subsystem for better clarity. Also drop finish_tmp_packfile() as a standalone function in favor of embedding it in flush_packfile_transaction() directly. Signed-off-by: Justin Tobler <jltobler@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Justin Tobler committed Sep 16, 2025 at 13:29 UTC ed0f5f93e9f0b0b3cc1a37ee5b10b625590f08c8
1 file changed +36 -44
object-file.c
+36 -44
@@ -667,7 +667,7 @@ void hash_object_file(const struct git_hash_algo *algo, const void *buf,
667 write_object_file_prepare(algo, buf, len, type, oid, hdr, &hdrlen);
668 }
669
670 -struct bulk_checkin_packfile {
670 +struct transaction_packfile {
671 char *pack_tmp_name;
672 struct hashfile *f;
673 off_t offset;
@@ -682,10 +682,10 @@ struct odb_transaction {
682 struct object_database *odb;
683
684 struct tmp_objdir *objdir;
685 - struct bulk_checkin_packfile packfile;
685 + struct transaction_packfile packfile;
686 };
687
688 -static void prepare_loose_object_bulk_checkin(struct odb_transaction *transaction)
688 +static void prepare_loose_object_transaction(struct odb_transaction *transaction)
689 {
690 /*
691 * We lazily create the temporary object directory
@@ -701,7 +701,7 @@ static void prepare_loose_object_bulk_checkin(struct odb_transaction *transactio
701 tmp_objdir_replace_primary_odb(transaction->objdir, 0);
702 }
703
704 -static void fsync_loose_object_bulk_checkin(struct odb_transaction *transaction,
704 +static void fsync_loose_object_transaction(struct odb_transaction *transaction,
705 int fd, const char *filename)
706 {
707 /*
@@ -722,7 +722,7 @@ static void fsync_loose_object_bulk_checkin(struct odb_transaction *transaction,
722 /*
723 * Cleanup after batch-mode fsync_object_files.
724 */
725 -static void flush_batch_fsync(struct odb_transaction *transaction)
725 +static void flush_loose_object_transaction(struct odb_transaction *transaction)
726 {
727 struct strbuf temp_path = STRBUF_INIT;
728 struct tempfile *temp;
@@ -733,7 +733,7 @@ static void flush_batch_fsync(struct odb_transaction *transaction)
733 /*
734 * Issue a full hardware flush against a temporary file to ensure
735 * that all objects are durable before any renames occur. The code in
736 - * fsync_loose_object_bulk_checkin has already issued a writeout
736 + * fsync_loose_object_transaction has already issued a writeout
737 * request, but it has not flushed any writeback cache in the storage
738 * hardware or any filesystem logs. This fsync call acts as a barrier
739 * to ensure that the data in each new object file is durable before
@@ -762,7 +762,7 @@ static void close_loose_object(struct odb_source *source,
762 goto out;
763
764 if (batch_fsync_enabled(FSYNC_COMPONENT_LOOSE_OBJECT))
765 - fsync_loose_object_bulk_checkin(source->odb->transaction, fd, filename);
765 + fsync_loose_object_transaction(source->odb->transaction, fd, filename);
766 else if (fsync_object_files > 0)
767 fsync_or_die(fd, filename);
768 else
@@ -940,7 +940,7 @@ static int write_loose_object(struct odb_source *source,
940 static struct strbuf filename = STRBUF_INIT;
941
942 if (batch_fsync_enabled(FSYNC_COMPONENT_LOOSE_OBJECT))
943 - prepare_loose_object_bulk_checkin(source->odb->transaction);
943 + prepare_loose_object_transaction(source->odb->transaction);
944
945 odb_loose_path(source, &filename, oid);
946
@@ -1029,7 +1029,7 @@ int stream_loose_object(struct odb_source *source,
1029 int hdrlen;
1030
1031 if (batch_fsync_enabled(FSYNC_COMPONENT_LOOSE_OBJECT))
1032 - prepare_loose_object_bulk_checkin(source->odb->transaction);
1032 + prepare_loose_object_transaction(source->odb->transaction);
1033
1034 /* Since oid is not determined, save tmp file to odb path. */
1035 strbuf_addf(&filename, "%s/", source->path);
@@ -1349,10 +1349,10 @@ static int already_written(struct odb_transaction *transaction,
1349 }
1350
1351 /* Lazily create backing packfile for the state */
1352 -static void prepare_to_stream(struct odb_transaction *transaction,
1353 - unsigned flags)
1352 +static void prepare_packfile_transaction(struct odb_transaction *transaction,
1353 + unsigned flags)
1354 {
1355 - struct bulk_checkin_packfile *state = &transaction->packfile;
1355 + struct transaction_packfile *state = &transaction->packfile;
1356 if (!(flags & INDEX_WRITE_OBJECT) || state->f)
1357 return;
1358
@@ -1381,7 +1381,7 @@ static void prepare_to_stream(struct odb_transaction *transaction,
1381 * status before calling us just in case we ask it to call us again
1382 * with a new pack.
1383 */
1384 -static int stream_blob_to_pack(struct bulk_checkin_packfile *state,
1384 +static int stream_blob_to_pack(struct transaction_packfile *state,
1385 struct git_hash_ctx *ctx, off_t *already_hashed_to,
1386 int fd, size_t size, const char *path,
1387 unsigned flags)
@@ -1457,28 +1457,13 @@ static int stream_blob_to_pack(struct bulk_checkin_packfile *state,
1457 return 0;
1458 }
1459
1460 -static void finish_tmp_packfile(struct odb_transaction *transaction,
1461 - struct strbuf *basename,
1462 - unsigned char hash[])
1460 +static void flush_packfile_transaction(struct odb_transaction *transaction)
1461 {
1464 - struct bulk_checkin_packfile *state = &transaction->packfile;
1465 - struct repository *repo = transaction->odb->repo;
1466 - char *idx_tmp_name = NULL;
1467 -
1468 - stage_tmp_packfiles(repo, basename, state->pack_tmp_name,
1469 - state->written, state->nr_written, NULL,
1470 - &state->pack_idx_opts, hash, &idx_tmp_name);
1471 - rename_tmp_packfile_idx(repo, basename, &idx_tmp_name);
1472 -
1473 - free(idx_tmp_name);
1474 -}
1475 -
1476 -static void flush_bulk_checkin_packfile(struct odb_transaction *transaction)
1477 -{
1478 - struct bulk_checkin_packfile *state = &transaction->packfile;
1462 + struct transaction_packfile *state = &transaction->packfile;
1463 struct repository *repo = transaction->odb->repo;
1464 unsigned char hash[GIT_MAX_RAWSZ];
1465 struct strbuf packname = STRBUF_INIT;
1466 + char *idx_tmp_name = NULL;
1467
1468 if (!state->f)
1469 return;
@@ -1503,11 +1488,16 @@ static void flush_bulk_checkin_packfile(struct odb_transaction *transaction)
1488 repo_get_object_directory(transaction->odb->repo),
1489 hash_to_hex_algop(hash, repo->hash_algo));
1490
1506 - finish_tmp_packfile(transaction, &packname, hash);
1491 + stage_tmp_packfiles(repo, &packname, state->pack_tmp_name,
1492 + state->written, state->nr_written, NULL,
1493 + &state->pack_idx_opts, hash, &idx_tmp_name);
1494 + rename_tmp_packfile_idx(repo, &packname, &idx_tmp_name);
1495 +
1496 for (uint32_t i = 0; i < state->nr_written; i++)
1497 free(state->written[i]);
1498
1499 clear_exit:
1500 + free(idx_tmp_name);
1501 free(state->pack_tmp_name);
1502 free(state->written);
1503 memset(state, 0, sizeof(*state));
@@ -1535,11 +1525,12 @@ clear_exit:
1525 * binary blobs, they generally do not want to get any conversion, and
1526 * callers should avoid this code path when filters are requested.
1527 */
1538 -static int index_blob_bulk_checkin(struct odb_transaction *transaction,
1539 - struct object_id *result_oid, int fd, size_t size,
1540 - const char *path, unsigned flags)
1528 +static int index_blob_packfile_transaction(struct odb_transaction *transaction,
1529 + struct object_id *result_oid, int fd,
1530 + size_t size, const char *path,
1531 + unsigned flags)
1532 {
1542 - struct bulk_checkin_packfile *state = &transaction->packfile;
1533 + struct transaction_packfile *state = &transaction->packfile;
1534 off_t seekback, already_hashed_to;
1535 struct git_hash_ctx ctx;
1536 unsigned char obuf[16384];
@@ -1560,14 +1551,14 @@ static int index_blob_bulk_checkin(struct odb_transaction *transaction,
1551 if ((flags & INDEX_WRITE_OBJECT) != 0) {
1552 CALLOC_ARRAY(idx, 1);
1553
1563 - prepare_to_stream(transaction, flags);
1554 + prepare_packfile_transaction(transaction, flags);
1555 hashfile_checkpoint_init(state->f, &checkpoint);
1556 }
1557
1558 already_hashed_to = 0;
1559
1560 while (1) {
1570 - prepare_to_stream(transaction, flags);
1561 + prepare_packfile_transaction(transaction, flags);
1562 if (idx) {
1563 hashfile_checkpoint(state->f, &checkpoint);
1564 idx->offset = state->offset;
@@ -1585,7 +1576,7 @@ static int index_blob_bulk_checkin(struct odb_transaction *transaction,
1576 BUG("should not happen");
1577 hashfile_truncate(state->f, &checkpoint);
1578 state->offset = checkpoint.offset;
1588 - flush_bulk_checkin_packfile(transaction);
1579 + flush_packfile_transaction(transaction);
1580 if (lseek(fd, seekback, SEEK_SET) == (off_t)-1)
1581 return error("cannot seek back");
1582 }
@@ -1632,9 +1623,10 @@ int index_fd(struct index_state *istate, struct object_id *oid,
1623 struct odb_transaction *transaction;
1624
1625 transaction = begin_odb_transaction(the_repository->objects);
1635 - ret = index_blob_bulk_checkin(the_repository->objects->transaction,
1636 - oid, fd, xsize_t(st->st_size),
1637 - path, flags);
1626 + ret = index_blob_packfile_transaction(the_repository->objects->transaction,
1627 + oid, fd,
1628 + xsize_t(st->st_size),
1629 + path, flags);
1630 end_odb_transaction(transaction);
1631 }
1632
@@ -1996,8 +1988,8 @@ void end_odb_transaction(struct odb_transaction *transaction)
1988 */
1989 ASSERT(transaction == transaction->odb->transaction);
1990
1999 - flush_batch_fsync(transaction);
2000 - flush_bulk_checkin_packfile(transaction);
1991 + flush_loose_object_transaction(transaction);
1992 + flush_packfile_transaction(transaction);
1993 transaction->odb->transaction = NULL;
1994 free(transaction);
1995 }