]> git.ipfire.org Git - thirdparty/git.git/commitdiff
odb/transaction: make `write_object_stream()` pluggable
authorJustin Tobler <jltobler@gmail.com>
Thu, 2 Apr 2026 21:32:20 +0000 (16:32 -0500)
committerJunio C Hamano <gitster@pobox.com>
Thu, 2 Apr 2026 21:52:58 +0000 (14:52 -0700)
How an ODB transaction handles writing objects is expected to vary
between implementations. Introduce a new `write_object_stream()`
callback in `struct odb_transaction` to make this function pluggable.
Rename `index_blob_packfile_transaction()` to
`odb_transaction_files_write_object_stream()` and wire it up for use
with `struct odb_transaction_files` accordingly.

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 7fa2b9239f409cdd8216fd6761a5406580d39c98..65356998f3f7855ac66eed6c820bfd71926ba180 100644 (file)
@@ -1577,9 +1577,10 @@ clear_exit:
  * binary blobs, they generally do not want to get any conversion, and
  * callers should avoid this code path when filters are requested.
  */
-static int index_blob_packfile_transaction(struct odb_transaction *base,
-                                          struct odb_write_stream *stream,
-                                          size_t size, struct object_id *result_oid)
+static int odb_transaction_files_write_object_stream(struct odb_transaction *base,
+                                                    struct odb_write_stream *stream,
+                                                    size_t size,
+                                                    struct object_id *result_oid)
 {
        struct odb_transaction_files *transaction = container_of(base,
                                                                 struct odb_transaction_files,
@@ -1663,10 +1664,10 @@ int index_fd(struct index_state *istate, struct object_id *oid,
                        struct object_database *odb = the_repository->objects;
                        struct odb_transaction *transaction = odb_transaction_begin(odb);
 
-                       ret = index_blob_packfile_transaction(odb->transaction,
-                                                             &stream,
-                                                             xsize_t(st->st_size),
-                                                             oid);
+                       ret = odb_transaction_write_object_stream(odb->transaction,
+                                                                 &stream,
+                                                                 xsize_t(st->st_size),
+                                                                 oid);
                        odb_transaction_commit(transaction);
                } else {
                        ret = hash_blob_stream(&stream,
@@ -2131,6 +2132,7 @@ struct odb_transaction *odb_transaction_files_begin(struct odb_source *source)
        transaction = xcalloc(1, sizeof(*transaction));
        transaction->base.source = source;
        transaction->base.commit = odb_transaction_files_commit;
+       transaction->base.write_object_stream = odb_transaction_files_write_object_stream;
 
        return &transaction->base;
 }
index 592ac840759a074ccf74236df43e331a8a1a9683..b16e07aebfc5ac3675f1296240a5f2565a67413e 100644 (file)
@@ -26,3 +26,10 @@ void odb_transaction_commit(struct odb_transaction *transaction)
        transaction->source->odb->transaction = NULL;
        free(transaction);
 }
+
+int odb_transaction_write_object_stream(struct odb_transaction *transaction,
+                                       struct odb_write_stream *stream,
+                                       size_t len, struct object_id *oid)
+{
+       return transaction->write_object_stream(transaction, stream, len, oid);
+}
index a56e392f217f4f20a8c768df4e7b2c86c6468e04..854fda06f576e49ac7f3c3427b583cb71b62c37a 100644 (file)
  *
  * Each ODB source is expected to implement its own transaction handling.
  */
-struct odb_transaction;
-typedef void (*odb_transaction_commit_fn)(struct odb_transaction *transaction);
 struct odb_transaction {
        /* The ODB source the transaction is opened against. */
        struct odb_source *source;
 
        /* The ODB source specific callback invoked to commit a transaction. */
-       odb_transaction_commit_fn commit;
+       void (*commit)(struct odb_transaction *transaction);
+
+       /*
+        * This callback is expected to write the given object stream into
+        * the ODB transaction. Note that for now, only blobs support streaming.
+        *
+        * The resulting object ID shall be written into the out pointer. The
+        * callback is expected to return 0 on success, a negative error code
+        * otherwise.
+        */
+       int (*write_object_stream)(struct odb_transaction *transaction,
+                                  struct odb_write_stream *stream, size_t len,
+                                  struct object_id *oid);
 };
 
 /*
@@ -35,4 +45,13 @@ struct odb_transaction *odb_transaction_begin(struct object_database *odb);
  */
 void odb_transaction_commit(struct odb_transaction *transaction);
 
+/*
+ * Writes the object in the provided stream into the transaction. The resulting
+ * object ID is written into the out pointer. Returns 0 on success, a negative
+ * error code otherwise.
+ */
+int odb_transaction_write_object_stream(struct odb_transaction *transaction,
+                                       struct odb_write_stream *stream,
+                                       size_t len, struct object_id *oid);
+
 #endif