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>
Justin Tobler committed
Aug 22, 2025 at 16:35 UTC
ddc0b56ad77d7c86145a6a1774f05f9d11bf2337
1 file changed
+36
-31
bulk-checkin.c
+36
-31
@@ -38,25 +38,26 @@ struct odb_transaction {
38
struct bulk_checkin_packfile packfile;
39
};
40
41
-static void finish_tmp_packfile(struct strbuf *basename,
42
- const char *pack_tmp_name,
43
- struct pack_idx_entry **written_list,
44
- uint32_t nr_written,
45
- struct pack_idx_option *pack_idx_opts,
41
+static void finish_tmp_packfile(struct odb_transaction *transaction,
42
+ struct strbuf *basename,
43
unsigned char hash[])
44
{
45
+ struct bulk_checkin_packfile *state = &transaction->packfile;
46
+ struct repository *repo = transaction->odb->repo;
47
char *idx_tmp_name = NULL;
48
50
- stage_tmp_packfiles(the_repository, basename, pack_tmp_name,
51
- written_list, nr_written, NULL, pack_idx_opts, hash,
52
- &idx_tmp_name);
53
- rename_tmp_packfile_idx(the_repository, basename, &idx_tmp_name);
49
+ stage_tmp_packfiles(repo, basename, state->pack_tmp_name,
50
+ state->written, state->nr_written, NULL,
51
+ &state->pack_idx_opts, hash, &idx_tmp_name);
52
+ rename_tmp_packfile_idx(repo, basename, &idx_tmp_name);
53
54
free(idx_tmp_name);
55
}
56
58
-static void flush_bulk_checkin_packfile(struct bulk_checkin_packfile *state)
57
+static void flush_bulk_checkin_packfile(struct odb_transaction *transaction)
58
{
59
+ struct bulk_checkin_packfile *state = &transaction->packfile;
60
+ struct repository *repo = transaction->odb->repo;
61
unsigned char hash[GIT_MAX_RAWSZ];
62
struct strbuf packname = STRBUF_INIT;
63
@@ -73,17 +74,17 @@ static void flush_bulk_checkin_packfile(struct bulk_checkin_packfile *state)
74
CSUM_HASH_IN_STREAM | CSUM_FSYNC | CSUM_CLOSE);
75
} else {
76
int fd = finalize_hashfile(state->f, hash, FSYNC_COMPONENT_PACK, 0);
76
- fixup_pack_header_footer(the_hash_algo, fd, hash, state->pack_tmp_name,
77
+ fixup_pack_header_footer(repo->hash_algo, fd, hash, state->pack_tmp_name,
78
state->nr_written, hash,
79
state->offset);
80
close(fd);
81
}
82
82
- strbuf_addf(&packname, "%s/pack/pack-%s.", repo_get_object_directory(the_repository),
83
- hash_to_hex(hash));
84
- finish_tmp_packfile(&packname, state->pack_tmp_name,
85
- state->written, state->nr_written,
86
- &state->pack_idx_opts, hash);
83
+ strbuf_addf(&packname, "%s/pack/pack-%s.",
84
+ repo_get_object_directory(transaction->odb->repo),
85
+ hash_to_hex_algop(hash, repo->hash_algo));
86
+
87
+ finish_tmp_packfile(transaction, &packname, hash);
88
for (uint32_t i = 0; i < state->nr_written; i++)
89
free(state->written[i]);
90
@@ -94,7 +95,7 @@ clear_exit:
95
96
strbuf_release(&packname);
97
/* Make objects we just wrote available to ourselves */
97
- reprepare_packed_git(the_repository);
98
+ reprepare_packed_git(repo);
99
}
100
101
/*
@@ -117,7 +118,8 @@ static void flush_batch_fsync(struct odb_transaction *transaction)
118
* to ensure that the data in each new object file is durable before
119
* the final name is visible.
120
*/
120
- strbuf_addf(&temp_path, "%s/bulk_fsync_XXXXXX", repo_get_object_directory(the_repository));
121
+ strbuf_addf(&temp_path, "%s/bulk_fsync_XXXXXX",
122
+ repo_get_object_directory(transaction->odb->repo));
123
temp = xmks_tempfile(temp_path.buf);
124
fsync_or_die(get_tempfile_fd(temp), get_tempfile_path(temp));
125
delete_tempfile(&temp);
@@ -131,16 +133,17 @@ static void flush_batch_fsync(struct odb_transaction *transaction)
133
transaction->objdir = NULL;
134
}
135
134
-static int already_written(struct bulk_checkin_packfile *state, struct object_id *oid)
136
+static int already_written(struct odb_transaction *transaction,
137
+ struct object_id *oid)
138
{
139
/* The object may already exist in the repository */
137
- if (odb_has_object(the_repository->objects, oid,
140
+ if (odb_has_object(transaction->odb, oid,
141
HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
142
return 1;
143
144
/* Might want to keep the list sorted */
142
- for (uint32_t i = 0; i < state->nr_written; i++)
143
- if (oideq(&state->written[i]->oid, oid))
145
+ for (uint32_t i = 0; i < transaction->packfile.nr_written; i++)
146
+ if (oideq(&transaction->packfile.written[i]->oid, oid))
147
return 1;
148
149
/* This is a new object we need to keep */
@@ -239,13 +242,15 @@ static int stream_blob_to_pack(struct bulk_checkin_packfile *state,
242
}
243
244
/* Lazily create backing packfile for the state */
242
-static void prepare_to_stream(struct bulk_checkin_packfile *state,
245
+static void prepare_to_stream(struct odb_transaction *transaction,
246
unsigned flags)
247
{
248
+ struct bulk_checkin_packfile *state = &transaction->packfile;
249
if (!(flags & INDEX_WRITE_OBJECT) || state->f)
250
return;
251
248
- state->f = create_tmp_packfile(the_repository, &state->pack_tmp_name);
252
+ state->f = create_tmp_packfile(transaction->odb->repo,
253
+ &state->pack_tmp_name);
254
reset_pack_idx_option(&state->pack_idx_opts);
255
256
/* Pretend we are going to write only one object */
@@ -272,21 +277,21 @@ int index_blob_bulk_checkin(struct odb_transaction *transaction,
277
278
header_len = format_object_header((char *)obuf, sizeof(obuf),
279
OBJ_BLOB, size);
275
- the_hash_algo->init_fn(&ctx);
280
+ transaction->odb->repo->hash_algo->init_fn(&ctx);
281
git_hash_update(&ctx, obuf, header_len);
282
283
/* Note: idx is non-NULL when we are writing */
284
if ((flags & INDEX_WRITE_OBJECT) != 0) {
285
CALLOC_ARRAY(idx, 1);
286
282
- prepare_to_stream(state, flags);
287
+ prepare_to_stream(transaction, flags);
288
hashfile_checkpoint_init(state->f, &checkpoint);
289
}
290
291
already_hashed_to = 0;
292
293
while (1) {
289
- prepare_to_stream(state, flags);
294
+ prepare_to_stream(transaction, flags);
295
if (idx) {
296
hashfile_checkpoint(state->f, &checkpoint);
297
idx->offset = state->offset;
@@ -304,7 +309,7 @@ int index_blob_bulk_checkin(struct odb_transaction *transaction,
309
BUG("should not happen");
310
hashfile_truncate(state->f, &checkpoint);
311
state->offset = checkpoint.offset;
307
- flush_bulk_checkin_packfile(state);
312
+ flush_bulk_checkin_packfile(transaction);
313
if (lseek(fd, seekback, SEEK_SET) == (off_t) -1)
314
return error("cannot seek back");
315
}
@@ -313,7 +318,7 @@ int index_blob_bulk_checkin(struct odb_transaction *transaction,
318
return 0;
319
320
idx->crc32 = crc32_end(state->f);
316
- if (already_written(state, result_oid)) {
321
+ if (already_written(transaction, result_oid)) {
322
hashfile_truncate(state->f, &checkpoint);
323
state->offset = checkpoint.offset;
324
free(idx);
@@ -338,7 +343,7 @@ void prepare_loose_object_bulk_checkin(struct odb_transaction *transaction)
343
if (!transaction || transaction->objdir)
344
return;
345
341
- transaction->objdir = tmp_objdir_create(the_repository, "bulk-fsync");
346
+ transaction->objdir = tmp_objdir_create(transaction->odb->repo, "bulk-fsync");
347
if (transaction->objdir)
348
tmp_objdir_replace_primary_odb(transaction->objdir, 0);
349
}
@@ -379,7 +384,7 @@ void flush_odb_transaction(struct odb_transaction *transaction)
384
return;
385
386
flush_batch_fsync(transaction);
382
- flush_bulk_checkin_packfile(&transaction->packfile);
387
+ flush_bulk_checkin_packfile(transaction);
388
}
389
390
void end_odb_transaction(struct odb_transaction *transaction)