diff --git a/object-file.c b/object-file.c index 85654b3fb9..5172ff33ed 100644 --- a/object-file.c +++ b/object-file.c @@ -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; diff --git a/odb/transaction.c b/odb/transaction.c index b20d6a16f8..20d3f43f54 100644 --- a/odb/transaction.c +++ b/odb/transaction.c @@ -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); +} diff --git a/odb/transaction.h b/odb/transaction.h index 7898770071..536458297b 100644 --- a/odb/transaction.h +++ b/odb/transaction.h @@ -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