]> git.ipfire.org Git - thirdparty/git.git/commitdiff
odb/source-loose: wire up `write_object_stream()` callback
authorPatrick Steinhardt <ps@pks.im>
Thu, 21 May 2026 08:22:36 +0000 (10:22 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 21 May 2026 13:35:20 +0000 (22:35 +0900)
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>
object-file.h
odb/source-files.c
odb/source-loose.c

index d30f1b10b2eb36ba1ed1b65be2a3444577ee291f..b864351372616561b12f16f3029c4d1c60b90a1b 100644 (file)
@@ -23,7 +23,17 @@ int index_path(struct index_state *istate, struct object_id *oid, const char *pa
 struct object_info;
 struct odb_source;
 
-int odb_source_loose_write_stream(struct odb_source_loose *loose,
+/*
+ * Write the given stream into the loose object source. The only difference to
+ * the generic implementation of this function is that we don't perform an
+ * object existence check here.
+ *
+ * TODO: We should stop exposing this function altogether and move it into
+ * "odb/source-loose.c". This requires a couple of refactorings though to make
+ * `force_object_loose()` generic and is thus postponed to a later point in
+ * time.
+ */
+int odb_source_loose_write_stream(struct odb_source_loose *source,
                                  struct odb_write_stream *stream, size_t len,
                                  struct object_id *oid);
 
index 2ba1def776e006c2600abedee9f1a47bf31bb4fd..83f8066c67dd3ce70c3421acd65834bae5487dad 100644 (file)
@@ -7,6 +7,7 @@
 #include "odb.h"
 #include "odb/source.h"
 #include "odb/source-files.h"
+#include "odb/source-loose.h"
 #include "packfile.h"
 #include "strbuf.h"
 #include "write-or-die.h"
@@ -175,7 +176,7 @@ static int odb_source_files_write_object_stream(struct odb_source *source,
                                                struct object_id *oid)
 {
        struct odb_source_files *files = odb_source_files_downcast(source);
-       return odb_source_loose_write_stream(files->loose, stream, len, oid);
+       return odb_source_write_object_stream(&files->loose->base, stream, len, oid);
 }
 
 static int odb_source_files_begin_transaction(struct odb_source *source,
index da8a60dba1c04c9b7d4f944dedbc081515b01ad5..e52fc289a24102431ea9e8b6040a2e3103da7c20 100644 (file)
@@ -632,6 +632,19 @@ static int odb_source_loose_write_object(struct odb_source *source,
        return 0;
 }
 
+static int odb_source_loose_write_object_stream(struct odb_source *source,
+                                               struct odb_write_stream *in_stream,
+                                               size_t len,
+                                               struct object_id *oid)
+{
+       /*
+        * TODO: the implementation should be moved here, see the comment on
+        * the called function in "object-file.h".
+        */
+       struct odb_source_loose *loose = odb_source_loose_downcast(source);
+       return odb_source_loose_write_stream(loose, in_stream, len, oid);
+}
+
 static void odb_source_loose_clear_cache(struct odb_source_loose *loose)
 {
        oidtree_clear(loose->cache);
@@ -692,6 +705,7 @@ struct odb_source_loose *odb_source_loose_new(struct odb_source_files *files)
        loose->base.count_objects = odb_source_loose_count_objects;
        loose->base.freshen_object = odb_source_loose_freshen_object;
        loose->base.write_object = odb_source_loose_write_object;
+       loose->base.write_object_stream = odb_source_loose_write_object_stream;
 
        if (!is_absolute_path(loose->base.path))
                chdir_notify_register(NULL, odb_source_loose_reparent, loose);