odb/transaction: make `write_object_stream()` pluggable
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>
Justin Tobler committed
May 14, 2026 at 13:37 UTC
08b6afb2a2dbf762e3d9fa7abd78090b9afbd1a8
3 files changed
+38
-10
object-file.c
+9
-7
@@ -1578,9 +1578,10 @@ clear_exit:
1578
* binary blobs, they generally do not want to get any conversion, and
1579
* callers should avoid this code path when filters are requested.
1580
*/
1581
-static int index_blob_packfile_transaction(struct odb_transaction *base,
1582
- struct odb_write_stream *stream,
1583
- size_t size, struct object_id *result_oid)
1581
+static int odb_transaction_files_write_object_stream(struct odb_transaction *base,
1582
+ struct odb_write_stream *stream,
1583
+ size_t size,
1584
+ struct object_id *result_oid)
1585
{
1586
struct odb_transaction_files *transaction = container_of(base,
1587
struct odb_transaction_files,
@@ -1664,10 +1665,10 @@ int index_fd(struct index_state *istate, struct object_id *oid,
1665
struct object_database *odb = the_repository->objects;
1666
struct odb_transaction *transaction = odb_transaction_begin(odb);
1667
1667
- ret = index_blob_packfile_transaction(odb->transaction,
1668
- &stream,
1669
- xsize_t(st->st_size),
1670
- oid);
1668
+ ret = odb_transaction_write_object_stream(odb->transaction,
1669
+ &stream,
1670
+ xsize_t(st->st_size),
1671
+ oid);
1672
odb_transaction_commit(transaction);
1673
} else {
1674
ret = hash_blob_stream(&stream,
@@ -2132,6 +2133,7 @@ struct odb_transaction *odb_transaction_files_begin(struct odb_source *source)
2133
transaction = xcalloc(1, sizeof(*transaction));
2134
transaction->base.source = source;
2135
transaction->base.commit = odb_transaction_files_commit;
2136
+ transaction->base.write_object_stream = odb_transaction_files_write_object_stream;
2137
2138
return &transaction->base;
2139
}
odb/transaction.c
+7
@@ -26,3 +26,10 @@ void odb_transaction_commit(struct odb_transaction *transaction)
26
transaction->source->odb->transaction = NULL;
27
free(transaction);
28
}
29
+
30
+int odb_transaction_write_object_stream(struct odb_transaction *transaction,
31
+ struct odb_write_stream *stream,
32
+ size_t len, struct object_id *oid)
33
+{
34
+ return transaction->write_object_stream(transaction, stream, len, oid);
35
+}
odb/transaction.h
+22
-3
@@ -12,14 +12,24 @@
12
*
13
* Each ODB source is expected to implement its own transaction handling.
14
*/
15
-struct odb_transaction;
16
-typedef void (*odb_transaction_commit_fn)(struct odb_transaction *transaction);
15
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. */
22
- odb_transaction_commit_fn commit;
20
+ void (*commit)(struct odb_transaction *transaction);
21
+
22
+ /*
23
+ * This callback is expected to write the given object stream into
24
+ * the ODB transaction. Note that for now, only blobs support streaming.
25
+ *
26
+ * The resulting object ID shall be written into the out pointer. The
27
+ * callback is expected to return 0 on success, a negative error code
28
+ * otherwise.
29
+ */
30
+ int (*write_object_stream)(struct odb_transaction *transaction,
31
+ struct odb_write_stream *stream, size_t len,
32
+ struct object_id *oid);
33
};
34
35
/*
@@ -35,4 +45,13 @@ struct odb_transaction *odb_transaction_begin(struct object_database *odb);
45
*/
46
void odb_transaction_commit(struct odb_transaction *transaction);
47
48
+/*
49
+ * Writes the object in the provided stream into the transaction. The resulting
50
+ * object ID is written into the out pointer. Returns 0 on success, a negative
51
+ * error code otherwise.
52
+ */
53
+int odb_transaction_write_object_stream(struct odb_transaction *transaction,
54
+ struct odb_write_stream *stream,
55
+ size_t len, struct object_id *oid);
56
+
57
#endif