Merge commit

26e1e47b474fbf223d0f53c8e13e0891fdb8b968

Merge branch 'jt/receive-pack-pluggable-writes'

The 'git receive-pack' command has been updated to use a new ODB
transaction interface for writing incoming packfiles, making it more
backend-agnostic.

* jt/receive-pack-pluggable-writes:
  odb/transaction: add transaction interface to write packfiles
  odb: return temporary ODB source when set
  builtin/receive-pack: explicitly pass packfile fd
  builtin/receive-pack: report unpack errors via strbuf
  builtin/receive-pack: lift global state out of unpack()
  builtin/receive-pack: read unpack limit config lazily
  builtin/receive-pack: pass shallow file explicitly
  odb/transaction: add transaction finalize interface
  builtin/receive-pack: properly clean up keep files

Junio C Hamano <gitster@pobox.com> · 2026-08-31 15:24 UTC

Browse files

Combined diff: only what this merge did beyond taking one side. Added lines are colored by the parent they came from; bold lines came from none of them; removed lines are red.

3 files changed, +43 −15
modified object-file.c
@@@ -963,14 -969,18 +971,14 @@@ int index_fd(struct index_state *istate
971 if (!inflight)
972 odb_transaction_begin_or_die(odb, &transaction, 0);
973 ret = odb_transaction_write_object_stream(transaction,
- &stream,
- xsize_t(st->st_size),
- oid);
974 + stream, oid);
975 if (!inflight)
- odb_transaction_commit(transaction);
976 + odb_transaction_commit_and_finalize_or_die(transaction);
977 } else {
- ret = hash_blob_stream(&stream,
- the_repository->hash_algo, oid,
- xsize_t(st->st_size));
978 + ret = hash_stream(stream, the_repository->hash_algo, oid);
979 }
980
- odb_write_stream_release(&stream);
981 + odb_stream_close(stream);
982 }
983
984 close(fd);
modified odb/transaction.c
@@@ -39,12 -53,19 +53,19 @@@ int odb_transaction_finalize(struct odb
53 }
54
55 int odb_transaction_write_object_stream(struct odb_transaction *transaction,
- struct odb_write_stream *stream,
- size_t len, struct object_id *oid)
56 + struct odb_stream *stream,
57 + struct object_id *oid)
58 {
- return transaction->write_object_stream(transaction, stream, len, oid);
59 + return transaction->write_object_stream(transaction, stream, oid);
60 }
61
62 + int odb_transaction_write_pack(struct odb_transaction *transaction, int pack_fd,
63 + struct strbuf *err_msg,
64 + const struct odb_transaction_write_pack_opts *opts)
65 + {
66 + return transaction->write_pack(transaction, pack_fd, err_msg, opts);
67 + }
68 +
69 int odb_transaction_env(struct odb_transaction *transaction, struct strvec *env)
70 {
71 if (!transaction)
modified odb/transaction.h
@@@ -22,17 -66,33 +66,33 @@@ struct odb_transaction
66 */
67 int (*commit)(struct odb_transaction *transaction);
68
69 + /*
70 + * Optional ODB source specific callback invoked when the transaction
71 + * needs to perform any deferred cleanup after objects have been
72 + * committed. Returns 0 on success, a negative error code otherwise.
73 + */
74 + int (*finalize)(struct odb_transaction *transaction);
75 +
76 /*
77 * This callback is expected to write the given object stream into
- * the ODB transaction. Note that for now, only blobs support streaming.
78 + * the ODB transaction.
79 *
80 * The resulting object ID shall be written into the out pointer. The
81 * callback is expected to return 0 on success, a negative error code
82 * otherwise.
83 */
84 int (*write_object_stream)(struct odb_transaction *transaction,
- struct odb_write_stream *stream, size_t len,
85 + struct odb_stream *stream,
86 struct object_id *oid);
87 + /*
88 + * This callback is expected to ingest the packfile readable via
89 + * `pack_fd` into the transaction. Returns 0 on success, a negative
90 + * error code otherwise. On failure, a human-readable description is
91 + * appended to `err_msg`.
92 + */
93 + int (*write_pack)(struct odb_transaction *transaction, int pack_fd,
94 + struct strbuf *err_msg,
95 + const struct odb_transaction_write_pack_opts *opts);
96
97 /*
98 * This callback is expected to populate the provided strvec with the
@@@ -81,9 -157,18 +157,18 @@@ static inline void odb_transaction_comm
157 * error code otherwise.
158 */
159 int odb_transaction_write_object_stream(struct odb_transaction *transaction,
- struct odb_write_stream *stream,
- size_t len, struct object_id *oid);
160 + struct odb_stream *stream,
161 + struct object_id *oid);
162
163 + /*
164 + * Ingests the packfile readable via `pack_fd` into the transaction. Returns 0
165 + * on success, a negative error code otherwise. On failure, a human-readable
166 + * description is appended to `err_msg`.
167 + */
168 + int odb_transaction_write_pack(struct odb_transaction *transaction, int pack_fd,
169 + struct strbuf *err_msg,
170 + const struct odb_transaction_write_pack_opts *opts);
171 +
172 /*
173 * Populates the provided strvec with the environment variables that a child
174 * process should inherit so that its object writes participate in the