Skip to content

Commit ed0f5f9

Browse files
jltoblergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 78839e9 commit ed0f5f9

File tree

1 file changed

+36
-44
lines changed

1 file changed

+36
-44
lines changed

object-file.c

Lines changed: 36 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ void hash_object_file(const struct git_hash_algo *algo, const void *buf,
667667
write_object_file_prepare(algo, buf, len, type, oid, hdr, &hdrlen);
668668
}
669669

670-
struct bulk_checkin_packfile {
670+
struct transaction_packfile {
671671
char *pack_tmp_name;
672672
struct hashfile *f;
673673
off_t offset;
@@ -682,10 +682,10 @@ struct odb_transaction {
682682
struct object_database *odb;
683683

684684
struct tmp_objdir *objdir;
685-
struct bulk_checkin_packfile packfile;
685+
struct transaction_packfile packfile;
686686
};
687687

688-
static void prepare_loose_object_bulk_checkin(struct odb_transaction *transaction)
688+
static void prepare_loose_object_transaction(struct odb_transaction *transaction)
689689
{
690690
/*
691691
* We lazily create the temporary object directory
@@ -701,7 +701,7 @@ static void prepare_loose_object_bulk_checkin(struct odb_transaction *transactio
701701
tmp_objdir_replace_primary_odb(transaction->objdir, 0);
702702
}
703703

704-
static void fsync_loose_object_bulk_checkin(struct odb_transaction *transaction,
704+
static void fsync_loose_object_transaction(struct odb_transaction *transaction,
705705
int fd, const char *filename)
706706
{
707707
/*
@@ -722,7 +722,7 @@ static void fsync_loose_object_bulk_checkin(struct odb_transaction *transaction,
722722
/*
723723
* Cleanup after batch-mode fsync_object_files.
724724
*/
725-
static void flush_batch_fsync(struct odb_transaction *transaction)
725+
static void flush_loose_object_transaction(struct odb_transaction *transaction)
726726
{
727727
struct strbuf temp_path = STRBUF_INIT;
728728
struct tempfile *temp;
@@ -733,7 +733,7 @@ static void flush_batch_fsync(struct odb_transaction *transaction)
733733
/*
734734
* Issue a full hardware flush against a temporary file to ensure
735735
* 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
737737
* request, but it has not flushed any writeback cache in the storage
738738
* hardware or any filesystem logs. This fsync call acts as a barrier
739739
* 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,
762762
goto out;
763763

764764
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);
766766
else if (fsync_object_files > 0)
767767
fsync_or_die(fd, filename);
768768
else
@@ -940,7 +940,7 @@ static int write_loose_object(struct odb_source *source,
940940
static struct strbuf filename = STRBUF_INIT;
941941

942942
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);
944944

945945
odb_loose_path(source, &filename, oid);
946946

@@ -1029,7 +1029,7 @@ int stream_loose_object(struct odb_source *source,
10291029
int hdrlen;
10301030

10311031
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);
10331033

10341034
/* Since oid is not determined, save tmp file to odb path. */
10351035
strbuf_addf(&filename, "%s/", source->path);
@@ -1349,10 +1349,10 @@ static int already_written(struct odb_transaction *transaction,
13491349
}
13501350

13511351
/* 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)
13541354
{
1355-
struct bulk_checkin_packfile *state = &transaction->packfile;
1355+
struct transaction_packfile *state = &transaction->packfile;
13561356
if (!(flags & INDEX_WRITE_OBJECT) || state->f)
13571357
return;
13581358

@@ -1381,7 +1381,7 @@ static void prepare_to_stream(struct odb_transaction *transaction,
13811381
* status before calling us just in case we ask it to call us again
13821382
* with a new pack.
13831383
*/
1384-
static int stream_blob_to_pack(struct bulk_checkin_packfile *state,
1384+
static int stream_blob_to_pack(struct transaction_packfile *state,
13851385
struct git_hash_ctx *ctx, off_t *already_hashed_to,
13861386
int fd, size_t size, const char *path,
13871387
unsigned flags)
@@ -1457,28 +1457,13 @@ static int stream_blob_to_pack(struct bulk_checkin_packfile *state,
14571457
return 0;
14581458
}
14591459

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)
14631461
{
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;
14791463
struct repository *repo = transaction->odb->repo;
14801464
unsigned char hash[GIT_MAX_RAWSZ];
14811465
struct strbuf packname = STRBUF_INIT;
1466+
char *idx_tmp_name = NULL;
14821467

14831468
if (!state->f)
14841469
return;
@@ -1503,11 +1488,16 @@ static void flush_bulk_checkin_packfile(struct odb_transaction *transaction)
15031488
repo_get_object_directory(transaction->odb->repo),
15041489
hash_to_hex_algop(hash, repo->hash_algo));
15051490

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+
15071496
for (uint32_t i = 0; i < state->nr_written; i++)
15081497
free(state->written[i]);
15091498

15101499
clear_exit:
1500+
free(idx_tmp_name);
15111501
free(state->pack_tmp_name);
15121502
free(state->written);
15131503
memset(state, 0, sizeof(*state));
@@ -1535,11 +1525,12 @@ static void flush_bulk_checkin_packfile(struct odb_transaction *transaction)
15351525
* binary blobs, they generally do not want to get any conversion, and
15361526
* callers should avoid this code path when filters are requested.
15371527
*/
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)
15411532
{
1542-
struct bulk_checkin_packfile *state = &transaction->packfile;
1533+
struct transaction_packfile *state = &transaction->packfile;
15431534
off_t seekback, already_hashed_to;
15441535
struct git_hash_ctx ctx;
15451536
unsigned char obuf[16384];
@@ -1560,14 +1551,14 @@ static int index_blob_bulk_checkin(struct odb_transaction *transaction,
15601551
if ((flags & INDEX_WRITE_OBJECT) != 0) {
15611552
CALLOC_ARRAY(idx, 1);
15621553

1563-
prepare_to_stream(transaction, flags);
1554+
prepare_packfile_transaction(transaction, flags);
15641555
hashfile_checkpoint_init(state->f, &checkpoint);
15651556
}
15661557

15671558
already_hashed_to = 0;
15681559

15691560
while (1) {
1570-
prepare_to_stream(transaction, flags);
1561+
prepare_packfile_transaction(transaction, flags);
15711562
if (idx) {
15721563
hashfile_checkpoint(state->f, &checkpoint);
15731564
idx->offset = state->offset;
@@ -1585,7 +1576,7 @@ static int index_blob_bulk_checkin(struct odb_transaction *transaction,
15851576
BUG("should not happen");
15861577
hashfile_truncate(state->f, &checkpoint);
15871578
state->offset = checkpoint.offset;
1588-
flush_bulk_checkin_packfile(transaction);
1579+
flush_packfile_transaction(transaction);
15891580
if (lseek(fd, seekback, SEEK_SET) == (off_t)-1)
15901581
return error("cannot seek back");
15911582
}
@@ -1632,9 +1623,10 @@ int index_fd(struct index_state *istate, struct object_id *oid,
16321623
struct odb_transaction *transaction;
16331624

16341625
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);
16381630
end_odb_transaction(transaction);
16391631
}
16401632

@@ -1996,8 +1988,8 @@ void end_odb_transaction(struct odb_transaction *transaction)
19961988
*/
19971989
ASSERT(transaction == transaction->odb->transaction);
19981990

1999-
flush_batch_fsync(transaction);
2000-
flush_bulk_checkin_packfile(transaction);
1991+
flush_loose_object_transaction(transaction);
1992+
flush_packfile_transaction(transaction);
20011993
transaction->odb->transaction = NULL;
20021994
free(transaction);
20031995
}

0 commit comments

Comments
 (0)