Files
git/odb/transaction.c
Justin Tobler ddf6aee9c6 odb/transaction: make write_object_stream() pluggable
How an ODB transaction handles writing objects is expected to vary
between implementations. Introduce a new `write_object_stream()`
callback in `struct odb_transaction` to make this function pluggable.
Rename `index_blob_packfile_transaction()` to
`odb_transaction_files_write_object_stream()` and wire it up for use
with `struct odb_transaction_files` accordingly.

Signed-off-by: Justin Tobler <jltobler@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-04-02 14:52:58 -07:00

36 lines
867 B
C

#include "git-compat-util.h"
#include "odb/source.h"
#include "odb/transaction.h"
struct odb_transaction *odb_transaction_begin(struct object_database *odb)
{
if (odb->transaction)
return NULL;
odb_source_begin_transaction(odb->sources, &odb->transaction);
return odb->transaction;
}
void odb_transaction_commit(struct odb_transaction *transaction)
{
if (!transaction)
return;
/*
* Ensure the transaction ending matches the pending transaction.
*/
ASSERT(transaction == transaction->source->odb->transaction);
transaction->commit(transaction);
transaction->source->odb->transaction = NULL;
free(transaction);
}
int odb_transaction_write_object_stream(struct odb_transaction *transaction,
struct odb_write_stream *stream,
size_t len, struct object_id *oid)
{
return transaction->write_object_stream(transaction, stream, len, oid);
}