Files
git/odb/transaction.c
Justin Tobler 48d730a16a odb/transaction: introduce ODB transaction flags
The temporary directory used by git-receive-pack(1) to write objects is
managed slightly differently than how it is done via ODB transactions:

  - The temporary directory is eagerly created upfront, instead of
    waiting for the first object write.

  - The prefix name of the temporary directory is "incoming" instead of
    "bulk-fsync".

In a subsequent commit, git-receive-pack(1) will use ODB transactions
instead of `tmp_objdir` directly. To provide a means to configure the
same transaction behavior, introduce `enum odb_transaction_flags` and
the ODB_TRANSACTION_RECEIVE flag intended as a signal for ODB
transactions using the "files" backend to be set up for
git-receive-pack(1). Transaction call sites are updated accordingly to
provide the required flag parameter.

Signed-off-by: Justin Tobler <jltobler@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-07-10 13:21:53 -07:00

55 lines
1.2 KiB
C

#include "git-compat-util.h"
#include "gettext.h"
#include "odb/source.h"
#include "odb/transaction.h"
int odb_transaction_begin(struct object_database *odb,
struct odb_transaction **out,
enum odb_transaction_flags flags)
{
int ret;
if (odb->transaction)
return error(_("object database transaction already pending"));
ret = odb_source_begin_transaction(odb->sources, out, flags);
if (!ret)
odb->transaction = *out;
return ret;
}
int odb_transaction_commit(struct odb_transaction *transaction)
{
int ret;
if (!transaction)
return 0;
/*
* Ensure the transaction ending matches the pending transaction.
*/
ASSERT(transaction == transaction->source->odb->transaction);
ret = transaction->commit(transaction);
transaction->source->odb->transaction = NULL;
free(transaction);
return ret;
}
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);
}
int odb_transaction_env(struct odb_transaction *transaction, struct strvec *env)
{
if (!transaction)
return 0;
return transaction->env(transaction, env);
}