git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/6] odb/transaction: propagate begin errors

From
Justin Tobler <jltobler@gmail.com>
Date
Jun 24, 2026, 04:19 UTC
Message-ID
<20260624041920.2601961-4-jltobler@gmail.com>
In-Reply-To
<20260624041920.2601961-1-jltobler@gmail.com>

When `odb_transaction_begin()` is invoked, the function returns the transaction pointer directly. There is no way for the backend to signal that it failed to set up its state, such as when creating the temporary object directory backing the transaction.

In a subsequent commit, git-receive-pack(1) starts using ODB transactions and needs to be able to report such failures rather than silently ignore them. Refactor `odb_transaction_begin()` to return an int error code and write the resulting transaction into an out parameter. Also introduce `odb_transaction_begin_or_die()` as a convenience for callsites that do not need to handle errors explicitly.

Signed-off-by: Justin Tobler <jltobler@gmail.com>
---
 builtin/add.c            |  2 +-
 builtin/unpack-objects.c |  2 +-
 builtin/update-index.c   |  2 +-
 cache-tree.c             |  2 +-
 object-file.c            |  3 ++-
 odb/transaction.c        | 16 +++++++++++-----
 odb/transaction.h        | 19 +++++++++++++++----
 read-cache.c             |  2 +-
 8 files changed, 33 insertions(+), 15 deletions(-)
diff --git a/builtin/add.c b/builtin/add.c
index c859f66519..3d5d9cfdb9 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -581,7 +581,7 @@ int cmd_add(int argc,
 		string_list_clear(&only_match_skip_worktree, 0);
 	}
 
-	transaction = odb_transaction_begin(repo->objects);
+	odb_transaction_begin_or_die(repo->objects, &transaction);
 
 	ps_matched = xcalloc(pathspec.nr, 1);
 	if (add_renormalize)
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index f3849bb654..d0136cdd99 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -598,7 +598,7 @@ static void unpack_all(void)
 		progress = start_progress(the_repository,
 					  _("Unpacking objects"), nr_objects);
 	CALLOC_ARRAY(obj_list, nr_objects);
-	transaction = odb_transaction_begin(the_repository->objects);
+	odb_transaction_begin_or_die(the_repository->objects, &transaction);
 	for (i = 0; i < nr_objects; i++) {
 		unpack_one(i);
 		display_progress(progress, i + 1);
diff --git a/builtin/update-index.c b/builtin/update-index.c
index 3d6646c318..17f3ea284c 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -1124,7 +1124,7 @@ int cmd_update_index(int argc,
 	 * Allow the object layer to optimize adding multiple objects in
 	 * a batch.
 	 */
-	transaction = odb_transaction_begin(the_repository->objects);
+	odb_transaction_begin_or_die(the_repository->objects, &transaction);
 	while (ctx.argc) {
 		if (parseopt_state != PARSE_OPT_DONE)
 			parseopt_state = parse_options_step(&ctx, options,
diff --git a/cache-tree.c b/cache-tree.c
index 184f7e2635..1a7dfed9cf 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -490,7 +490,7 @@ int cache_tree_update(struct index_state *istate, int flags)
 
 	trace_performance_enter();
 	trace2_region_enter("cache_tree", "update", istate->repo);
-	transaction = odb_transaction_begin(the_repository->objects);
+	odb_transaction_begin_or_die(the_repository->objects, &transaction);
 	i = update_one(istate->cache_tree, istate->cache, istate->cache_nr,
 		       "", 0, &skip, flags);
 	odb_transaction_commit(transaction);
diff --git a/object-file.c b/object-file.c
index 18c2df75fb..696f05dc2d 100644
--- a/object-file.c
+++ b/object-file.c
@@ -1389,8 +1389,9 @@ int index_fd(struct index_state *istate, struct object_id *oid,
 
 		if (flags & INDEX_WRITE_OBJECT) {
 			struct object_database *odb = the_repository->objects;
-			struct odb_transaction *transaction = odb_transaction_begin(odb);
+			struct odb_transaction *transaction;
 
+			odb_transaction_begin_or_die(odb, &transaction);
 			ret = odb_transaction_write_object_stream(odb->transaction,
 								  &stream,
 								  xsize_t(st->st_size),
diff --git a/odb/transaction.c b/odb/transaction.c
index b16e07aebf..d3de01db50 100644
--- a/odb/transaction.c
+++ b/odb/transaction.c
@@ -2,14 +2,20 @@
 #include "odb/source.h"
 #include "odb/transaction.h"
 
-struct odb_transaction *odb_transaction_begin(struct object_database *odb)
+int odb_transaction_begin(struct object_database *odb,
+			  struct odb_transaction **out)
 {
-	if (odb->transaction)
-		return NULL;
+	int ret;
 
-	odb_source_begin_transaction(odb->sources, &odb->transaction);
+	if (odb->transaction) {
+		*out = NULL;
+		return 0;
+	}
 
-	return odb->transaction;
+	ret = odb_source_begin_transaction(odb->sources, out);
+	odb->transaction = *out;
+
+	return ret;
 }
 
 void odb_transaction_commit(struct odb_transaction *transaction)
diff --git a/odb/transaction.h b/odb/transaction.h
index f4c1ebfaaa..cd6d50f2e5 100644
--- a/odb/transaction.h
+++ b/odb/transaction.h
@@ -1,6 +1,8 @@
 #ifndef ODB_TRANSACTION_H
 #define ODB_TRANSACTION_H
 
+#include "git-compat-util.h"
+#include "gettext.h"
 #include "odb.h"
 #include "odb/source.h"
 
@@ -33,11 +35,20 @@ struct odb_transaction {
 };
 
 /*
- * Starts an ODB transaction. Subsequent objects are written to the transaction
- * and not committed until odb_transaction_commit() is invoked on the
- * transaction. If the ODB already has a pending transaction, NULL is returned.
+ * Starts an ODB transaction and returns it via `out`. Subsequent objects are
+ * written to the transaction and not committed until odb_transaction_commit()
+ * is invoked on the transaction. Returns 0 on success and a negative value on
+ * error. If the ODB already has a pending transaction, `out` is set to NULL.
  */
-struct odb_transaction *odb_transaction_begin(struct object_database *odb);
+int odb_transaction_begin(struct object_database *odb,
+			  struct odb_transaction **out);
+
+static inline void odb_transaction_begin_or_die(struct object_database *odb,
+						struct odb_transaction **out)
+{
+	if (odb_transaction_begin(odb, out))
+		die(_("failed to start ODB transaction"));
+}
 
 /*
  * Commits an ODB transaction making the written objects visible. If the
diff --git a/read-cache.c b/read-cache.c
index 21ca58beea..db0bfa60fe 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -4042,7 +4042,7 @@ int add_files_to_cache(struct repository *repo, const char *prefix,
 	 * This function is invoked from commands other than 'add', which
 	 * may not have their own transaction active.
 	 */
-	transaction = odb_transaction_begin(repo->objects);
+	odb_transaction_begin_or_die(repo->objects, &transaction);
 	run_diff_files(&rev, DIFF_RACY_IS_MODIFIED);
 	odb_transaction_commit(transaction);
 
-- 
2.54.0.105.g59ff4886a5
Previous: Justin ToblerNext: Patrick Steinhardt
Message 14 of 90 in “receive-pack: use ODB transactions to stage object writes”
  1. 0/6 receive-pack: use ODB transactions to stage object writesJustin Tobler, Jun 24, 2026
  2. 1/6 object-file: rename files transaction prepare functionJustin Tobler, Jun 24, 2026
  3. Junio C HamanoJun 24, 2026
  4. Justin ToblerJun 29, 2026
  5. 2/6 object-file: propagate files transaction errorsJustin Tobler, Jun 24, 2026
  6. Patrick SteinhardtJun 24, 2026
  7. Justin ToblerJun 29, 2026
  8. Justin ToblerJun 29, 2026
  9. Patrick SteinhardtJun 30, 2026
  10. Justin ToblerJun 30, 2026
  11. Patrick SteinhardtJun 30, 2026
  12. Junio C HamanoJun 24, 2026
  13. Justin ToblerJun 29, 2026
  14. 3/6 odb/transaction: propagate begin errorsJustin Tobler, Jun 24, 2026
  15. Patrick SteinhardtJun 24, 2026
  16. Justin ToblerJun 29, 2026
  17. 5/6 odb/transaction: add transaction env interfaceJustin Tobler, Jun 24, 2026
  18. Patrick SteinhardtJun 24, 2026
  19. Justin ToblerJun 29, 2026
  20. 6/6 builtin/receive-pack: stage incoming objects via ODB transactionsJustin Tobler, Jun 24, 2026
  21. Patrick SteinhardtJun 24, 2026
  22. Justin ToblerJun 29, 2026
  23. Patrick SteinhardtJun 30, 2026
  24. 4/6 odb/transaction: propagate commit errorsJustin Tobler, Jun 24, 2026
  25. Patrick SteinhardtJun 24, 2026
  26. Justin ToblerJun 29, 2026
  27. Patrick SteinhardtJun 24, 2026
  28. Junio C HamanoJun 24, 2026
  29. 00/11 receive-pack: use ODB transactions to stage object writesJustin Tobler, Jul 8, 2026
  30. 01/11 object-file: rename files transaction prepare functionJustin Tobler, Jul 8, 2026
  31. 02/11 object-file: rename files transaction fsync functionJustin Tobler, Jul 8, 2026
  32. Patrick SteinhardtJul 8, 2026
  33. 03/11 object-file: embed transaction flush logic in commit functionJustin Tobler, Jul 8, 2026
  34. Patrick SteinhardtJul 8, 2026
  35. Justin ToblerJul 8, 2026
  36. 04/11 object-file: drop check for inflight transactionsJustin Tobler, Jul 8, 2026
  37. Patrick SteinhardtJul 8, 2026
  38. 05/11 object-file: propagate files transaction errorsJustin Tobler, Jul 8, 2026
  39. Patrick SteinhardtJul 8, 2026
  40. Justin ToblerJul 8, 2026
  41. 06/11 odb/transaction: propagate begin errorsJustin Tobler, Jul 8, 2026
  42. Patrick SteinhardtJul 8, 2026
  43. Justin ToblerJul 8, 2026
  44. Patrick SteinhardtJul 9, 2026
  45. 07/11 odb/transaction: propagate commit errorsJustin Tobler, Jul 8, 2026
  46. Patrick SteinhardtJul 8, 2026
  47. Justin ToblerJul 8, 2026
  48. 08/11 odb/transaction: add transaction env interfaceJustin Tobler, Jul 8, 2026
  49. 09/11 odb/transaction: introduce ODB transaction flagsJustin Tobler, Jul 8, 2026
  50. Patrick SteinhardtJul 8, 2026
  51. Justin ToblerJul 8, 2026
  52. 10/11 builtin/receive-pack: drop redundant tmpdir envJustin Tobler, Jul 8, 2026
  53. Patrick SteinhardtJul 8, 2026
  54. 11/11 builtin/receive-pack: stage incoming objects via ODB transactionsJustin Tobler, Jul 8, 2026
  55. Patrick SteinhardtJul 8, 2026
  56. Justin ToblerJul 8, 2026
  57. 00/11 receive-pack: use ODB transactions to stage object writesJustin Tobler, Jul 8, 2026
  58. 01/11 object-file: rename files transaction prepare functionJustin Tobler, Jul 8, 2026
  59. 02/11 object-file: rename files transaction fsync functionJustin Tobler, Jul 8, 2026
  60. 03/11 object-file: embed transaction flush logic in commit functionJustin Tobler, Jul 8, 2026
  61. Patrick SteinhardtJul 9, 2026
  62. 04/11 object-file: drop check for inflight transactionsJustin Tobler, Jul 8, 2026
  63. 05/11 object-file: propagate files transaction errorsJustin Tobler, Jul 8, 2026
  64. 06/11 odb/transaction: propagate begin errorsJustin Tobler, Jul 8, 2026
  65. Junio C HamanoJul 9, 2026
  66. Justin ToblerJul 9, 2026
  67. 07/11 odb/transaction: propagate commit errorsJustin Tobler, Jul 8, 2026
  68. 09/11 odb/transaction: introduce ODB transaction flagsJustin Tobler, Jul 8, 2026
  69. 10/11 builtin/receive-pack: drop redundant tmpdir envJustin Tobler, Jul 8, 2026
  70. 08/11 odb/transaction: add transaction env interfaceJustin Tobler, Jul 8, 2026
  71. Junio C HamanoJul 9, 2026
  72. Justin ToblerJul 9, 2026
  73. 11/11 builtin/receive-pack: stage incoming objects via ODB transactionsJustin Tobler, Jul 8, 2026
  74. Junio C HamanoJul 9, 2026
  75. Justin ToblerJul 10, 2026
  76. Junio C HamanoJul 10, 2026
  77. Patrick SteinhardtJul 9, 2026
  78. 00/11 receive-pack: use ODB transactions to stage object writesJustin Tobler, Jul 10, 2026
  79. 01/11 object-file: rename files transaction prepare functionJustin Tobler, Jul 10, 2026
  80. 02/11 object-file: rename files transaction fsync functionJustin Tobler, Jul 10, 2026
  81. 03/11 object-file: embed transaction flush logic in commit functionJustin Tobler, Jul 10, 2026
  82. 04/11 object-file: drop check for inflight transactionsJustin Tobler, Jul 10, 2026
  83. 05/11 object-file: propagate files transaction errorsJustin Tobler, Jul 10, 2026
  84. 06/11 odb/transaction: propagate begin errorsJustin Tobler, Jul 10, 2026
  85. 07/11 odb/transaction: propagate commit errorsJustin Tobler, Jul 10, 2026
  86. 08/11 odb/transaction: add transaction env interfaceJustin Tobler, Jul 10, 2026
  87. 10/11 builtin/receive-pack: drop redundant tmpdir envJustin Tobler, Jul 10, 2026
  88. 09/11 odb/transaction: introduce ODB transaction flagsJustin Tobler, Jul 10, 2026
  89. 11/11 builtin/receive-pack: stage incoming objects via ODB transactionsJustin Tobler, Jul 10, 2026
  90. Patrick SteinhardtJul 13, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.