odb/source-loose: move loose source into "odb/" subsystem

In subsequent patches we'll be turning `struct odb_source_loose` into a proper `struct odb_source`. As a first step towards this goal, move its struct out of "object-file.c" and into "odb/source-loose.c". This detaches the implementation of the loose object source from the generic object file code, following the same convention already used by the "files" and "in-memory" sources. No functional changes are intended. 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 514f039c9052c23047c310f911ba8c0c2e74a1c7
6 files changed +47 -28
Makefile
+1
@@ -1217,6 +1217,7 @@ LIB_OBJS += odb.o
1217 LIB_OBJS += odb/source.o
1218 LIB_OBJS += odb/source-files.o
1219 LIB_OBJS += odb/source-inmemory.o
1220 +LIB_OBJS += odb/source-loose.o
1221 LIB_OBJS += odb/streaming.o
1222 LIB_OBJS += odb/transaction.o
1223 LIB_OBJS += oid-array.o
meson.build
+1
@@ -405,6 +405,7 @@ libgit_sources = [
405 'odb/source.c',
406 'odb/source-files.c',
407 'odb/source-inmemory.c',
408 + 'odb/source-loose.c',
409 'odb/streaming.c',
410 'odb/transaction.c',
411 'oid-array.c',
object-file.c
-8
@@ -2205,14 +2205,6 @@ struct odb_transaction *odb_transaction_files_begin(struct odb_source *source)
2205 return &transaction->base;
2206 }
2207
2208 -struct odb_source_loose *odb_source_loose_new(struct odb_source *source)
2209 -{
2210 - struct odb_source_loose *loose;
2211 - CALLOC_ARRAY(loose, 1);
2212 - loose->source = source;
2213 - return loose;
2214 -}
2215 -
2208 void odb_source_loose_free(struct odb_source_loose *loose)
2209 {
2210 if (!loose)
object-file.h
+1 -20
@@ -4,6 +4,7 @@
4 #include "git-zlib.h"
5 #include "object.h"
6 #include "odb.h"
7 +#include "odb/source-loose.h"
8
9 struct index_state;
10
@@ -20,26 +21,6 @@ struct object_info;
21 struct odb_read_stream;
22 struct odb_source;
23
23 -struct odb_source_loose {
24 - struct odb_source *source;
25 -
26 - /*
27 - * Used to store the results of readdir(3) calls when we are OK
28 - * sacrificing accuracy due to races for speed. That includes
29 - * object existence with OBJECT_INFO_QUICK, as well as
30 - * our search for unique abbreviated hashes. Don't use it for tasks
31 - * requiring greater accuracy!
32 - *
33 - * Be sure to call odb_load_loose_cache() before using.
34 - */
35 - uint32_t subdir_seen[8]; /* 256 bits */
36 - struct oidtree *cache;
37 -
38 - /* Map between object IDs for loose objects. */
39 - struct loose_object_map *map;
40 -};
41 -
42 -struct odb_source_loose *odb_source_loose_new(struct odb_source *source);
24 void odb_source_loose_free(struct odb_source_loose *loose);
25
26 /* Reprepare the loose source by emptying the loose object cache. */
odb/source-loose.c new
+10
@@ -0,0 +1,10 @@
1 +#include "git-compat-util.h"
2 +#include "odb/source-loose.h"
3 +
4 +struct odb_source_loose *odb_source_loose_new(struct odb_source *source)
5 +{
6 + struct odb_source_loose *loose;
7 + CALLOC_ARRAY(loose, 1);
8 + loose->source = source;
9 + return loose;
10 +}
odb/source-loose.h new
+34
@@ -0,0 +1,34 @@
1 +#ifndef ODB_SOURCE_LOOSE_H
2 +#define ODB_SOURCE_LOOSE_H
3 +
4 +#include "odb/source.h"
5 +
6 +struct object_database;
7 +struct oidtree;
8 +
9 +/*
10 + * An object database source that stores its objects in loose format, one
11 + * file per object. This source is part of the files source.
12 + */
13 +struct odb_source_loose {
14 + struct odb_source *source;
15 +
16 + /*
17 + * Used to store the results of readdir(3) calls when we are OK
18 + * sacrificing accuracy due to races for speed. That includes
19 + * object existence with OBJECT_INFO_QUICK, as well as
20 + * our search for unique abbreviated hashes. Don't use it for tasks
21 + * requiring greater accuracy!
22 + *
23 + * Be sure to call odb_load_loose_cache() before using.
24 + */
25 + uint32_t subdir_seen[8]; /* 256 bits */
26 + struct oidtree *cache;
27 +
28 + /* Map between object IDs for loose objects. */
29 + struct loose_object_map *map;
30 +};
31 +
32 +struct odb_source_loose *odb_source_loose_new(struct odb_source *source);
33 +
34 +#endif