odb/transaction: add transaction env interface

The ODB transaction backend is responsible for creating/managing its own
staging area for writing objects. Other child processes spawned by Git
may need to access to uncommitted objects or write new objects in the
staging area though.

Introduce `odb_transaction_env()` which is expected to provide the set
of environment variables needed by a child process to access the
transaction staging area.

Signed-off-by: Justin Tobler <jltobler@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Justin Tobler
2026-06-23 23:19:19 -05:00
committed by Junio C Hamano
parent a72d74fa59
commit ffab7256ac
3 changed files with 38 additions and 0 deletions

View File

@@ -1689,6 +1689,16 @@ static int odb_transaction_files_commit(struct odb_transaction *base)
return 0;
}
static const char **odb_transaction_files_env(struct odb_transaction *base)
{
struct odb_transaction_files *transaction =
container_of(base, struct odb_transaction_files, base);
odb_transaction_files_prepare(&transaction->base);
return tmp_objdir_env(transaction->objdir);
}
int odb_transaction_files_begin(struct odb_source *source,
struct odb_transaction **out)
{
@@ -1704,6 +1714,7 @@ int odb_transaction_files_begin(struct odb_source *source,
transaction->base.source = source;
transaction->base.commit = odb_transaction_files_commit;
transaction->base.write_object_stream = odb_transaction_files_write_object_stream;
transaction->base.env = odb_transaction_files_env;
*out = &transaction->base;
return 0;

View File

@@ -46,3 +46,11 @@ int odb_transaction_write_object_stream(struct odb_transaction *transaction,
{
return transaction->write_object_stream(transaction, stream, len, oid);
}
const char **odb_transaction_env(struct odb_transaction *transaction)
{
if (!transaction)
return NULL;
return transaction->env(transaction);
}

View File

@@ -32,6 +32,16 @@ struct odb_transaction {
int (*write_object_stream)(struct odb_transaction *transaction,
struct odb_write_stream *stream, size_t len,
struct object_id *oid);
/*
* This callback is expected to return a NULL-terminated array of
* environment variables that a child process should inherit so
* that its object writes participate in the transaction. The
* returned array is owned by the backend and remains valid until
* the transaction ends. May return NULL when the backend does not
* need to expose any state to child processes.
*/
const char **(*env)(struct odb_transaction *transaction);
};
/*
@@ -65,4 +75,13 @@ int odb_transaction_write_object_stream(struct odb_transaction *transaction,
struct odb_write_stream *stream,
size_t len, struct object_id *oid);
/*
* Returns a NULL-terminated array of environment variables that a child
* process should inherit so that its object writes participate in the
* transaction, suitable for passing via child_process.env. Returns NULL if
* the transaction is NULL or the backend does not expose any state to child
* processes.
*/
const char **odb_transaction_env(struct odb_transaction *transaction);
#endif