]> git.ipfire.org Git - thirdparty/git.git/commitdiff
odb/transaction: propagate commit errors
authorJustin Tobler <jltobler@gmail.com>
Fri, 10 Jul 2026 16:37:18 +0000 (11:37 -0500)
committerJunio C Hamano <gitster@pobox.com>
Fri, 10 Jul 2026 20:21:53 +0000 (13:21 -0700)
When `odb_transaction_commit()` is invoked, the return value of the
backend commit callback is silently discarded. A backend has no way
to signal that committing failed, such as when the "files" backend
cannot migrate its temporary object directory into the permanent
ODB.

In a subsequent commit, git-receive-pack(1) starts using ODB transaction
to stage objects and consequently cares about such failures so it can
handle the error appropriately. Change the commit callback signature to
return an int error code and have `odb_transaction_commit()` forward it
accordingly.

Signed-off-by: Justin Tobler <jltobler@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
odb/transaction.c
odb/transaction.h

index b6da4a3942f8880412c741e4fec7faca4c1eec99..249ef4d9b7adde6dc47e862edbb424dadec8acf9 100644 (file)
@@ -18,19 +18,23 @@ int odb_transaction_begin(struct object_database *odb,
        return ret;
 }
 
-void odb_transaction_commit(struct odb_transaction *transaction)
+int odb_transaction_commit(struct odb_transaction *transaction)
 {
+       int ret;
+
        if (!transaction)
-               return;
+               return 0;
 
        /*
         * Ensure the transaction ending matches the pending transaction.
         */
        ASSERT(transaction == transaction->source->odb->transaction);
 
-       transaction->commit(transaction);
+       ret = transaction->commit(transaction);
        transaction->source->odb->transaction = NULL;
        free(transaction);
+
+       return ret;
 }
 
 int odb_transaction_write_object_stream(struct odb_transaction *transaction,
index f5c43187c94dd302445d529f3c20d90d90558de5..3b0a5a78e5927dd6d5e345c50b686f9ffda50d22 100644 (file)
@@ -54,10 +54,11 @@ static inline void odb_transaction_begin_or_die(struct object_database *odb,
 }
 
 /*
- * Commits an ODB transaction making the written objects visible. If the
- * specified transaction is NULL, the function is a no-op.
+ * Commits an ODB transaction making the written objects visible. 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.
  */
-void odb_transaction_commit(struct odb_transaction *transaction);
+int odb_transaction_commit(struct odb_transaction *transaction);
 
 /*
  * Writes the object in the provided stream into the transaction. The resulting