odb: store ODB source in `struct odb_transaction`

Each `struct odb_transaction` currently stores a reference to the `struct object_database`. Since transactions are handled per object source, instead store a reference to the source. Signed-off-by: Justin Tobler <jltobler@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Justin Tobler committed Feb 2, 2026 at 18:09 UTC 585e8dfa27050ce0a69c6e7ead0a3355912d4992
1 file changed +11 -11
object-file.c
+11 -11
@@ -711,7 +711,7 @@ struct transaction_packfile {
711 };
712
713 struct odb_transaction {
714 - struct object_database *odb;
714 + struct odb_source *source;
715
716 struct tmp_objdir *objdir;
717 struct transaction_packfile packfile;
@@ -728,7 +728,7 @@ static void prepare_loose_object_transaction(struct odb_transaction *transaction
728 if (!transaction || transaction->objdir)
729 return;
730
731 - transaction->objdir = tmp_objdir_create(transaction->odb->repo, "bulk-fsync");
731 + transaction->objdir = tmp_objdir_create(transaction->source->odb->repo, "bulk-fsync");
732 if (transaction->objdir)
733 tmp_objdir_replace_primary_odb(transaction->objdir, 0);
734 }
@@ -772,7 +772,7 @@ static void flush_loose_object_transaction(struct odb_transaction *transaction)
772 * the final name is visible.
773 */
774 strbuf_addf(&temp_path, "%s/bulk_fsync_XXXXXX",
775 - repo_get_object_directory(transaction->odb->repo));
775 + repo_get_object_directory(transaction->source->odb->repo));
776 temp = xmks_tempfile(temp_path.buf);
777 fsync_or_die(get_tempfile_fd(temp), get_tempfile_path(temp));
778 delete_tempfile(&temp);
@@ -1344,7 +1344,7 @@ static int already_written(struct odb_transaction *transaction,
1344 struct object_id *oid)
1345 {
1346 /* The object may already exist in the repository */
1347 - if (odb_has_object(transaction->odb, oid,
1347 + if (odb_has_object(transaction->source->odb, oid,
1348 HAS_OBJECT_RECHECK_PACKED | HAS_OBJECT_FETCH_PROMISOR))
1349 return 1;
1350
@@ -1365,7 +1365,7 @@ static void prepare_packfile_transaction(struct odb_transaction *transaction,
1365 if (!(flags & INDEX_WRITE_OBJECT) || state->f)
1366 return;
1367
1368 - state->f = create_tmp_packfile(transaction->odb->repo,
1368 + state->f = create_tmp_packfile(transaction->source->odb->repo,
1369 &state->pack_tmp_name);
1370 reset_pack_idx_option(&state->pack_idx_opts);
1371
@@ -1469,7 +1469,7 @@ static int stream_blob_to_pack(struct transaction_packfile *state,
1469 static void flush_packfile_transaction(struct odb_transaction *transaction)
1470 {
1471 struct transaction_packfile *state = &transaction->packfile;
1472 - struct repository *repo = transaction->odb->repo;
1472 + struct repository *repo = transaction->source->odb->repo;
1473 unsigned char hash[GIT_MAX_RAWSZ];
1474 struct strbuf packname = STRBUF_INIT;
1475 char *idx_tmp_name = NULL;
@@ -1494,7 +1494,7 @@ static void flush_packfile_transaction(struct odb_transaction *transaction)
1494 }
1495
1496 strbuf_addf(&packname, "%s/pack/pack-%s.",
1497 - repo_get_object_directory(transaction->odb->repo),
1497 + repo_get_object_directory(transaction->source->odb->repo),
1498 hash_to_hex_algop(hash, repo->hash_algo));
1499
1500 stage_tmp_packfiles(repo, &packname, state->pack_tmp_name,
@@ -1553,7 +1553,7 @@ static int index_blob_packfile_transaction(struct odb_transaction *transaction,
1553
1554 header_len = format_object_header((char *)obuf, sizeof(obuf),
1555 OBJ_BLOB, size);
1556 - transaction->odb->repo->hash_algo->init_fn(&ctx);
1556 + transaction->source->odb->repo->hash_algo->init_fn(&ctx);
1557 git_hash_update(&ctx, obuf, header_len);
1558
1559 /* Note: idx is non-NULL when we are writing */
@@ -1993,7 +1993,7 @@ struct odb_transaction *object_file_transaction_begin(struct odb_source *source)
1993 return NULL;
1994
1995 CALLOC_ARRAY(odb->transaction, 1);
1996 - odb->transaction->odb = odb;
1996 + odb->transaction->source = source;
1997
1998 return odb->transaction;
1999 }
@@ -2006,11 +2006,11 @@ void object_file_transaction_commit(struct odb_transaction *transaction)
2006 /*
2007 * Ensure the transaction ending matches the pending transaction.
2008 */
2009 - ASSERT(transaction == transaction->odb->transaction);
2009 + ASSERT(transaction == transaction->source->odb->transaction);
2010
2011 flush_loose_object_transaction(transaction);
2012 flush_packfile_transaction(transaction);
2013 - transaction->odb->transaction = NULL;
2013 + transaction->source->odb->transaction = NULL;
2014 free(transaction);
2015 }
2016