odb/source-loose: wire up `write_object_stream()` callback

Wire up the `write_object_stream()` callback. Note that we don't move the implementation into "odb/source-loose.c". This is because most of the logic to write loose objects is still contained in "object-file.c", and detangling that requires us to do some refactorings as explained in the preceding commit. So for now, the implementation of writing an object stream is still located in "object-file.c". Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jun 1, 2026 at 10:20 UTC e6a39bbe7a6bde5fb7de8d487e8f4ef928e6b751
3 files changed +27 -2
object-file.h
+11 -1
@@ -23,7 +23,17 @@ int index_path(struct index_state *istate, struct object_id *oid, const char *pa
23 struct object_info;
24 struct odb_source;
25
26 -int odb_source_loose_write_stream(struct odb_source_loose *loose,
26 +/*
27 + * Write the given stream into the loose object source. The only difference
28 + * from the generic implementation of this function is that we don't perform an
29 + * object existence check here.
30 + *
31 + * TODO: We should stop exposing this function altogether and move it into
32 + * "odb/source-loose.c". This requires a couple of refactorings though to make
33 + * `force_object_loose()` generic and is thus postponed to a later point in
34 + * time.
35 + */
36 +int odb_source_loose_write_stream(struct odb_source_loose *source,
37 struct odb_write_stream *stream, size_t len,
38 struct object_id *oid);
39
odb/source-files.c
+2 -1
@@ -7,6 +7,7 @@
7 #include "odb.h"
8 #include "odb/source.h"
9 #include "odb/source-files.h"
10 +#include "odb/source-loose.h"
11 #include "packfile.h"
12 #include "strbuf.h"
13 #include "write-or-die.h"
@@ -175,7 +176,7 @@ static int odb_source_files_write_object_stream(struct odb_source *source,
176 struct object_id *oid)
177 {
178 struct odb_source_files *files = odb_source_files_downcast(source);
178 - return odb_source_loose_write_stream(files->loose, stream, len, oid);
179 + return odb_source_write_object_stream(&files->loose->base, stream, len, oid);
180 }
181
182 static int odb_source_files_begin_transaction(struct odb_source *source,
odb/source-loose.c
+14
@@ -632,6 +632,19 @@ static int odb_source_loose_write_object(struct odb_source *source,
632 return 0;
633 }
634
635 +static int odb_source_loose_write_object_stream(struct odb_source *source,
636 + struct odb_write_stream *in_stream,
637 + size_t len,
638 + struct object_id *oid)
639 +{
640 + /*
641 + * TODO: the implementation should be moved here, see the comment on
642 + * the called function in "object-file.h".
643 + */
644 + struct odb_source_loose *loose = odb_source_loose_downcast(source);
645 + return odb_source_loose_write_stream(loose, in_stream, len, oid);
646 +}
647 +
648 static void odb_source_loose_clear_cache(struct odb_source_loose *loose)
649 {
650 oidtree_clear(loose->cache);
@@ -692,6 +705,7 @@ struct odb_source_loose *odb_source_loose_new(struct odb_source_files *files)
705 loose->base.count_objects = odb_source_loose_count_objects;
706 loose->base.freshen_object = odb_source_loose_freshen_object;
707 loose->base.write_object = odb_source_loose_write_object;
708 + loose->base.write_object_stream = odb_source_loose_write_object_stream;
709
710 if (!is_absolute_path(loose->base.path))
711 chdir_notify_register(NULL, odb_source_loose_reparent, loose);