]> git.ipfire.org Git - thirdparty/git.git/commitdiff
odb/transaction: add transaction env interface
authorJustin Tobler <jltobler@gmail.com>
Fri, 10 Jul 2026 16:37:19 +0000 (11:37 -0500)
committerJunio C Hamano <gitster@pobox.com>
Fri, 10 Jul 2026 20:21:53 +0000 (13:21 -0700)
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>
object-file.c
odb/transaction.c
odb/transaction.h

index f1ec9f6a8bbf92540aa98c565c343ba26958a989..7426a0c891a22c2989d2572669184638d73277a7 100644 (file)
@@ -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"
 
@@ -1685,6 +1686,20 @@ 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);
+       int ret;
+
+       ret = odb_transaction_files_prepare(&transaction->base);
+       if (!ret)
+               strvec_pushv(env, tmp_objdir_env(transaction->objdir));
+
+       return ret;
+}
+
 int odb_transaction_files_begin(struct odb_source *source,
                                struct odb_transaction **out)
 {
@@ -1694,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;
index 249ef4d9b7adde6dc47e862edbb424dadec8acf9..92ec8786a124612099a4f3a2b63f2ace3d3ee6a3 100644 (file)
@@ -43,3 +43,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);
+}
index 3b0a5a78e5927dd6d5e345c50b686f9ffda50d22..5e51ce5ca44b83bd5aeebaf34676a35bc6a81026 100644 (file)
@@ -34,6 +34,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);
 };
 
 /*
@@ -69,4 +77,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