odb/source-packed: wire up `read_object_info()` callback
Move the logic to read object info from a "packed" source into "odb/source-packed.c" and wire it up as the `read_object_info()` callback. Note that we also move around the supporting `find_pack_entry()`, but we still have to expose it to other callers that exist in "packfile.c". This will be fixed in subsequent commits though, where all callers in "packfile.c" will have been moved into "odb/source-packed.c", and at that point we'll be able to make `find_pack_entry()` file-local again. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Jun 17, 2026 at 08:39 UTC
64136a82075331d98fd1315fa957f69acb49885c
5 files changed
+79
-78
odb/source-files.c
+1
-1
@@ -55,7 +55,7 @@ static int odb_source_files_read_object_info(struct odb_source *source,
55
{
56
struct odb_source_files *files = odb_source_files_downcast(source);
57
58
- if (!packfile_store_read_object_info(files->packed, oid, oi, flags) ||
58
+ if (!odb_source_read_object_info(&files->packed->base, oid, oi, flags) ||
59
!odb_source_read_object_info(&files->loose->base, oid, oi, flags))
60
return 0;
61
odb/source-packed.c
+60
@@ -7,6 +7,65 @@
7
#include "odb/source-packed.h"
8
#include "packfile.h"
9
10
+int find_pack_entry(struct odb_source_packed *store,
11
+ const struct object_id *oid,
12
+ struct pack_entry *e)
13
+{
14
+ struct packfile_list_entry *l;
15
+
16
+ odb_source_packed_prepare(store);
17
+ if (store->midx && fill_midx_entry(store->midx, oid, e))
18
+ return 1;
19
+
20
+ for (l = store->packs.head; l; l = l->next) {
21
+ struct packed_git *p = l->pack;
22
+
23
+ if (!p->multi_pack_index && packfile_fill_entry(p, oid, e)) {
24
+ if (!store->skip_mru_updates)
25
+ packfile_list_prepend(&store->packs, p);
26
+ return 1;
27
+ }
28
+ }
29
+
30
+ return 0;
31
+}
32
+
33
+static int odb_source_packed_read_object_info(struct odb_source *source,
34
+ const struct object_id *oid,
35
+ struct object_info *oi,
36
+ enum object_info_flags flags)
37
+{
38
+ struct odb_source_packed *packed = odb_source_packed_downcast(source);
39
+ struct pack_entry e;
40
+ int ret;
41
+
42
+ /*
43
+ * In case the first read didn't surface the object, we have to reload
44
+ * packfiles. This may cause us to discover new packfiles that have
45
+ * been added since the last time we have prepared the packfile store.
46
+ */
47
+ if (flags & OBJECT_INFO_SECOND_READ)
48
+ odb_source_reprepare(source);
49
+
50
+ if (!find_pack_entry(packed, oid, &e))
51
+ return 1;
52
+
53
+ /*
54
+ * We know that the caller doesn't actually need the
55
+ * information below, so return early.
56
+ */
57
+ if (!oi)
58
+ return 0;
59
+
60
+ ret = packed_object_info(e.p, e.offset, oi);
61
+ if (ret < 0) {
62
+ mark_bad_packed_object(e.p, oid);
63
+ return -1;
64
+ }
65
+
66
+ return 0;
67
+}
68
+
69
void (*report_garbage)(unsigned seen_bits, const char *path);
70
71
static void report_helper(const struct string_list *list,
@@ -215,6 +274,7 @@ struct odb_source_packed *odb_source_packed_new(struct odb_source_files *parent)
274
packed->base.free = odb_source_packed_free;
275
packed->base.close = odb_source_packed_close;
276
packed->base.reprepare = odb_source_packed_reprepare;
277
+ packed->base.read_object_info = odb_source_packed_read_object_info;
278
279
if (!is_absolute_path(parent->base.path))
280
chdir_notify_register(NULL, odb_source_packed_reparent, packed);
odb/source-packed.h
+6
@@ -90,4 +90,10 @@ static inline struct odb_source_packed *odb_source_packed_downcast(struct odb_so
90
*/
91
void odb_source_packed_prepare(struct odb_source_packed *source);
92
93
+struct pack_entry;
94
+
95
+int find_pack_entry(struct odb_source_packed *store,
96
+ const struct object_id *oid,
97
+ struct pack_entry *e);
98
+
99
#endif
packfile.c
+8
-66
@@ -1895,9 +1895,9 @@ int is_pack_valid(struct packed_git *p)
1895
return !open_packed_git(p);
1896
}
1897
1898
-static int fill_pack_entry(const struct object_id *oid,
1899
- struct pack_entry *e,
1900
- struct packed_git *p)
1898
+int packfile_fill_entry(struct packed_git *p,
1899
+ const struct object_id *oid,
1900
+ struct pack_entry *e)
1901
{
1902
off_t offset;
1903
@@ -1923,29 +1923,6 @@ static int fill_pack_entry(const struct object_id *oid,
1923
return 1;
1924
}
1925
1926
-static int find_pack_entry(struct odb_source_packed *store,
1927
- const struct object_id *oid,
1928
- struct pack_entry *e)
1929
-{
1930
- struct packfile_list_entry *l;
1931
-
1932
- odb_source_packed_prepare(store);
1933
- if (store->midx && fill_midx_entry(store->midx, oid, e))
1934
- return 1;
1935
-
1936
- for (l = store->packs.head; l; l = l->next) {
1937
- struct packed_git *p = l->pack;
1938
-
1939
- if (!p->multi_pack_index && fill_pack_entry(oid, e, p)) {
1940
- if (!store->skip_mru_updates)
1941
- packfile_list_prepend(&store->packs, p);
1942
- return 1;
1943
- }
1944
- }
1945
-
1946
- return 0;
1947
-}
1948
-
1926
int packfile_store_freshen_object(struct odb_source_packed *store,
1927
const struct object_id *oid)
1928
{
@@ -1962,41 +1939,6 @@ int packfile_store_freshen_object(struct odb_source_packed *store,
1939
return 1;
1940
}
1941
1965
-int packfile_store_read_object_info(struct odb_source_packed *store,
1966
- const struct object_id *oid,
1967
- struct object_info *oi,
1968
- enum object_info_flags flags)
1969
-{
1970
- struct pack_entry e;
1971
- int ret;
1972
-
1973
- /*
1974
- * In case the first read didn't surface the object, we have to reload
1975
- * packfiles. This may cause us to discover new packfiles that have
1976
- * been added since the last time we have prepared the packfile store.
1977
- */
1978
- if (flags & OBJECT_INFO_SECOND_READ)
1979
- odb_source_reprepare(&store->base);
1980
-
1981
- if (!find_pack_entry(store, oid, &e))
1982
- return 1;
1983
-
1984
- /*
1985
- * We know that the caller doesn't actually need the
1986
- * information below, so return early.
1987
- */
1988
- if (!oi)
1989
- return 0;
1990
-
1991
- ret = packed_object_info(e.p, e.offset, oi);
1992
- if (ret < 0) {
1993
- mark_bad_packed_object(e.p, oid);
1994
- return -1;
1995
- }
1996
-
1997
- return 0;
1998
-}
1999
-
1942
static void maybe_invalidate_kept_pack_cache(struct odb_source_packed *store,
1943
unsigned flags)
1944
{
@@ -2053,7 +1995,7 @@ int has_object_pack(struct repository *r, const struct object_id *oid)
1995
odb_prepare_alternates(r->objects);
1996
for (source = r->objects->sources; source; source = source->next) {
1997
struct odb_source_files *files = odb_source_files_downcast(source);
2056
- if (!packfile_store_read_object_info(files->packed, oid, NULL, 0))
1998
+ if (!odb_source_read_object_info(&files->packed->base, oid, NULL, 0))
1999
return 1;
2000
}
2001
@@ -2074,7 +2016,7 @@ int has_object_kept_pack(struct repository *r, const struct object_id *oid,
2016
2017
for (; *cache; cache++) {
2018
struct packed_git *p = *cache;
2077
- if (fill_pack_entry(oid, &e, p))
2019
+ if (packfile_fill_entry(p, oid, &e))
2020
return 1;
2021
}
2022
}
@@ -2208,8 +2150,8 @@ static int for_each_prefixed_object_in_midx(
2150
if (data->request) {
2151
struct object_info oi = *data->request;
2152
2211
- ret = packfile_store_read_object_info(store, current,
2212
- &oi, 0);
2153
+ ret = odb_source_read_object_info(&store->base, current,
2154
+ &oi, 0);
2155
if (ret)
2156
goto out;
2157
@@ -2259,7 +2201,7 @@ static int for_each_prefixed_object_in_pack(
2201
if (data->request) {
2202
struct object_info oi = *data->request;
2203
2262
- ret = packfile_store_read_object_info(store, &oid, &oi, 0);
2204
+ ret = odb_source_read_object_info(&store->base, &oid, &oi, 0);
2205
if (ret)
2206
goto out;
2207
packfile.h
+4
-11
@@ -128,17 +128,6 @@ int packfile_store_read_object_stream(struct odb_read_stream **out,
128
struct odb_source_packed *store,
129
const struct object_id *oid);
130
131
-/*
132
- * Try to read the object identified by its ID from the object store and
133
- * populate the object info with its data. Returns 1 in case the object was
134
- * not found, 0 if it was and read successfully, and a negative error code in
135
- * case the object was corrupted.
136
- */
137
-int packfile_store_read_object_info(struct odb_source_packed *store,
138
- const struct object_id *oid,
139
- struct object_info *oi,
140
- enum object_info_flags flags);
141
-
131
/*
132
* Open the packfile and add it to the store if it isn't yet known. Returns
133
* either the newly opened packfile or the preexisting packfile. Returns a
@@ -340,6 +329,10 @@ off_t nth_packed_object_offset(const struct packed_git *, uint32_t n);
329
*/
330
off_t find_pack_entry_one(const struct object_id *oid, struct packed_git *);
331
332
+int packfile_fill_entry(struct packed_git *p,
333
+ const struct object_id *oid,
334
+ struct pack_entry *e);
335
+
336
int is_pack_valid(struct packed_git *);
337
void *unpack_entry(struct repository *r, struct packed_git *, off_t, enum object_type *, unsigned long *);
338
unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, size_t *sizep);