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 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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Justin Tobler committed Jul 10, 2026 at 11:37 UTC 28fbc0676936e2c024f3973066bec6b2bbfed610
3 files changed +41
object-file.c
+16
@@ -27,6 +27,7 @@
27 #include "path.h"
28 #include "read-cache-ll.h"
29 #include "setup.h"
30 +#include "strvec.h"
31 #include "tempfile.h"
32 #include "tmp-objdir.h"
33
@@ -1685,6 +1686,20 @@ static int odb_transaction_files_commit(struct odb_transaction *base)
1686 return 0;
1687 }
1688
1689 +static int odb_transaction_files_env(struct odb_transaction *base,
1690 + struct strvec *env)
1691 +{
1692 + struct odb_transaction_files *transaction =
1693 + container_of(base, struct odb_transaction_files, base);
1694 + int ret;
1695 +
1696 + ret = odb_transaction_files_prepare(&transaction->base);
1697 + if (!ret)
1698 + strvec_pushv(env, tmp_objdir_env(transaction->objdir));
1699 +
1700 + return ret;
1701 +}
1702 +
1703 int odb_transaction_files_begin(struct odb_source *source,
1704 struct odb_transaction **out)
1705 {
@@ -1694,6 +1709,7 @@ int odb_transaction_files_begin(struct odb_source *source,
1709 transaction->base.source = source;
1710 transaction->base.commit = odb_transaction_files_commit;
1711 transaction->base.write_object_stream = odb_transaction_files_write_object_stream;
1712 + transaction->base.env = odb_transaction_files_env;
1713 *out = &transaction->base;
1714
1715 return 0;
odb/transaction.c
+8
@@ -43,3 +43,11 @@ int odb_transaction_write_object_stream(struct odb_transaction *transaction,
43 {
44 return transaction->write_object_stream(transaction, stream, len, oid);
45 }
46 +
47 +int odb_transaction_env(struct odb_transaction *transaction, struct strvec *env)
48 +{
49 + if (!transaction)
50 + return 0;
51 +
52 + return transaction->env(transaction, env);
53 +}
odb/transaction.h
+17
@@ -34,6 +34,14 @@ struct odb_transaction {
34 int (*write_object_stream)(struct odb_transaction *transaction,
35 struct odb_write_stream *stream, size_t len,
36 struct object_id *oid);
37 +
38 + /*
39 + * This callback is expected to populate the provided strvec with the
40 + * environment variables that a child process should inherit so that its
41 + * object writes participate in the transaction. Returns 0 on success, a
42 + * negative error code otherwise.
43 + */
44 + int (*env)(struct odb_transaction *transaction, struct strvec *env);
45 };
46
47 /*
@@ -69,4 +77,13 @@ int odb_transaction_write_object_stream(struct odb_transaction *transaction,
77 struct odb_write_stream *stream,
78 size_t len, struct object_id *oid);
79
80 +/*
81 + * Populates the provided strvec with the environment variables that a child
82 + * process should inherit so that its object writes participate in the
83 + * transaction, suitable for using via child_process.env. Returns 0 on success,
84 + * a negative error code otherwise. Note that, if the specified transaction is
85 + * NULL, the function is a no-op and no error is returned.
86 + */
87 +int odb_transaction_env(struct odb_transaction *transaction, struct strvec *env);
88 +
89 #endif