[PATCH v2 08/11] odb/transaction: add transaction env interface
- From
Justin Tobler <jltobler@gmail.com>
- Date
- Jul 8, 2026, 04:14 UTC
- Message-ID
- <20260708041412.1157499-9-jltobler@gmail.com>
- In-Reply-To
- <20260708041412.1157499-1-jltobler@gmail.com>
The ODB transaction backend is responsible for creating/managing its own staging area for writing objects. Other child processes spawned by Git may need 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's staging area.
Signed-off-by: Justin Tobler <jltobler@gmail.com> --- object-file.c | 14 ++++++++++++++ odb/transaction.c | 8 ++++++++ odb/transaction.h | 17 +++++++++++++++++ 3 files changed, 39 insertions(+)
diff --git a/object-file.c b/object-file.c index cd1aa36462..9b8ee6f36c 100644 --- a/object-file.c +++ b/object-file.c @@ -27,6 +27,7 @@ #include "path.h" #include "read-cache-ll.h" #include "setup.h" +#include "strvec.h" #include "tempfile.h" #include "tmp-objdir.h" @@ -1687,6 +1688,18 @@ static int odb_transaction_files_commit(struct odb_transaction *base) return 0; } +static int odb_transaction_files_env(struct odb_transaction *base, + struct strvec *env) +{ + struct odb_transaction_files *transaction = + container_of(base, struct odb_transaction_files, base); + + odb_transaction_files_prepare(&transaction->base); + strvec_pushv(env, tmp_objdir_env(transaction->objdir)); + + return 0; +} + int odb_transaction_files_begin(struct odb_source *source, struct odb_transaction **out) { @@ -1696,6 +1709,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; diff --git a/odb/transaction.c b/odb/transaction.c index 51af2c9a61..acb1c967e7 100644 --- a/odb/transaction.c +++ b/odb/transaction.c @@ -44,3 +44,11 @@ int odb_transaction_write_object_stream(struct odb_transaction *transaction, { 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); +} diff --git a/odb/transaction.h b/odb/transaction.h index 9557ee0fd2..1c6c97a53e 100644 --- a/odb/transaction.h +++ b/odb/transaction.h @@ -35,6 +35,14 @@ 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 populate the provided strvec with the + * environment variables that a child process should inherit so that its + * object writes participate in the transaction. Returns 0 on success, a + * negative error code otherwise. + */ + int (*env)(struct odb_transaction *transaction, struct strvec *env); }; /* @@ -70,4 +78,13 @@ int odb_transaction_write_object_stream(struct odb_transaction *transaction, struct odb_write_stream *stream, size_t len, struct object_id *oid); +/* + * Populates the provided strvec with the environment variables that a child + * process should inherit so that its object writes participate in the + * transaction, suitable for using via child_process.env. Returns 0 on success, + * a negative error code otherwise. Note that, if the specified transaction is + * NULL, the function is a no-op and no error is returned. + */ +int odb_transaction_env(struct odb_transaction *transaction, struct strvec *env); + #endif
-- 2.55.0.122.gf85a7e6620