object-file: propagate files transaction errors

The "files" transaction backend may encounter errors related to managing the temporary directory used to stage objects, but silently ignores these errors. Instead return errors encountered in the `odb_transaction_files_{prepare,begin,commit}()` interfaces to allow callers to handle them as needed. 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 6d017185e3b4052354fca3a40e8453bd85624896
4 files changed +26 -16
object-file.c
+18 -8
@@ -499,7 +499,7 @@ struct odb_transaction_files {
499 struct transaction_packfile packfile;
500 };
501
502 -static void odb_transaction_files_prepare(struct odb_transaction *base)
502 +static int odb_transaction_files_prepare(struct odb_transaction *base)
503 {
504 struct odb_transaction_files *transaction =
505 container_of_or_null(base, struct odb_transaction_files, base);
@@ -511,11 +511,15 @@ static void odb_transaction_files_prepare(struct odb_transaction *base)
511 * added at the time they call odb_transaction_files_begin.
512 */
513 if (!transaction || transaction->objdir)
514 - return;
514 + return 0;
515
516 transaction->objdir = tmp_objdir_create(base->source->odb->repo, "bulk-fsync");
517 - if (transaction->objdir)
518 - tmp_objdir_replace_primary_odb(transaction->objdir, 0);
517 + if (!transaction->objdir)
518 + return error(_("unable to create temporary object directory"));
519 +
520 + tmp_objdir_replace_primary_odb(transaction->objdir, 0);
521 +
522 + return 0;
523 }
524
525 static void odb_transaction_files_fsync(struct odb_transaction *base,
@@ -1637,7 +1641,7 @@ out:
1641 return ret;
1642 }
1643
1640 -static void odb_transaction_files_commit(struct odb_transaction *base)
1644 +static int odb_transaction_files_commit(struct odb_transaction *base)
1645 {
1646 struct odb_transaction_files *transaction =
1647 container_of(base, struct odb_transaction_files, base);
@@ -1666,14 +1670,19 @@ static void odb_transaction_files_commit(struct odb_transaction *base)
1670 * Make the object files visible in the primary ODB after their data is
1671 * fully durable.
1672 */
1669 - tmp_objdir_migrate(transaction->objdir);
1673 + if (tmp_objdir_migrate(transaction->objdir))
1674 + return error(_("unable to migrate temporary objects"));
1675 +
1676 transaction->objdir = NULL;
1677 }
1678
1679 flush_packfile_transaction(transaction);
1680 +
1681 + return 0;
1682 }
1683
1676 -struct odb_transaction *odb_transaction_files_begin(struct odb_source *source)
1684 +int odb_transaction_files_begin(struct odb_source *source,
1685 + struct odb_transaction **out)
1686 {
1687 struct odb_transaction_files *transaction;
1688
@@ -1681,6 +1690,7 @@ struct odb_transaction *odb_transaction_files_begin(struct odb_source *source)
1690 transaction->base.source = source;
1691 transaction->base.commit = odb_transaction_files_commit;
1692 transaction->base.write_object_stream = odb_transaction_files_write_object_stream;
1693 + *out = &transaction->base;
1694
1685 - return &transaction->base;
1695 + return 0;
1696 }
object-file.h
+2 -1
@@ -196,6 +196,7 @@ struct odb_transaction;
196 * multiple objects. odb_transaction_files_commit must be called
197 * to make new objects visible.
198 */
199 -struct odb_transaction *odb_transaction_files_begin(struct odb_source *source);
199 +int odb_transaction_files_begin(struct odb_source *source,
200 + struct odb_transaction **out);
201
202 #endif /* OBJECT_FILE_H */
odb/source-files.c
+1 -5
@@ -182,11 +182,7 @@ static int odb_source_files_write_object_stream(struct odb_source *source,
182 static int odb_source_files_begin_transaction(struct odb_source *source,
183 struct odb_transaction **out)
184 {
185 - struct odb_transaction *tx = odb_transaction_files_begin(source);
186 - if (!tx)
187 - return -1;
188 - *out = tx;
189 - return 0;
185 + return odb_transaction_files_begin(source, out);
186 }
187
188 static int odb_source_files_read_alternates(struct odb_source *source,
odb/transaction.h
+5 -2
@@ -16,8 +16,11 @@ struct odb_transaction {
16 /* The ODB source the transaction is opened against. */
17 struct odb_source *source;
18
19 - /* The ODB source specific callback invoked to commit a transaction. */
20 - void (*commit)(struct odb_transaction *transaction);
19 + /*
20 + * The ODB source specific callback invoked to commit a transaction.
21 + * Returns 0 on success, a negative error code otherwise.
22 + */
23 + int (*commit)(struct odb_transaction *transaction);
24
25 /*
26 * This callback is expected to write the given object stream into