odb/source-packed: wire up `freshen_object()` callback
Move `packfile_store_freshen_object()` and from "packfile.c" into "odb/source-packed.c" and wire it up as the `freshen_object()` callback of the "packed" source. Note that this removes the last external caller of `find_pack_entry()` from "packfile.c", which means that we can now make this function static. 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
98189bdd0a789115e3bb5ec5d5312ce71d6f59b0
5 files changed
+24
-29
odb/source-files.c
+1
-1
@@ -152,7 +152,7 @@ static int odb_source_files_freshen_object(struct odb_source *source,
152
const struct object_id *oid)
153
{
154
struct odb_source_files *files = odb_source_files_downcast(source);
155
- if (packfile_store_freshen_object(files->packed, oid) ||
155
+ if (odb_source_freshen_object(&files->packed->base, oid) ||
156
odb_source_freshen_object(&files->loose->base, oid))
157
return 1;
158
return 0;
odb/source-packed.c
+23
-3
@@ -9,9 +9,9 @@
9
#include "odb/streaming.h"
10
#include "packfile.h"
11
12
-int find_pack_entry(struct odb_source_packed *store,
13
- const struct object_id *oid,
14
- struct pack_entry *e)
12
+static int find_pack_entry(struct odb_source_packed *store,
13
+ const struct object_id *oid,
14
+ struct pack_entry *e)
15
{
16
struct packfile_list_entry *l;
17
@@ -482,6 +482,25 @@ static int odb_source_packed_find_abbrev_len(struct odb_source *source,
482
return 0;
483
}
484
485
+static int odb_source_packed_freshen_object(struct odb_source *source,
486
+ const struct object_id *oid)
487
+{
488
+ struct odb_source_packed *packed = odb_source_packed_downcast(source);
489
+ struct pack_entry e;
490
+
491
+ if (!find_pack_entry(packed, oid, &e))
492
+ return 0;
493
+ if (e.p->is_cruft)
494
+ return 0;
495
+ if (e.p->freshened)
496
+ return 1;
497
+ if (utime(e.p->pack_name, NULL))
498
+ return 0;
499
+ e.p->freshened = 1;
500
+
501
+ return 1;
502
+}
503
+
504
void (*report_garbage)(unsigned seen_bits, const char *path);
505
506
static void report_helper(const struct string_list *list,
@@ -695,6 +714,7 @@ struct odb_source_packed *odb_source_packed_new(struct odb_source_files *parent)
714
packed->base.for_each_object = odb_source_packed_for_each_object;
715
packed->base.count_objects = odb_source_packed_count_objects;
716
packed->base.find_abbrev_len = odb_source_packed_find_abbrev_len;
717
+ packed->base.freshen_object = odb_source_packed_freshen_object;
718
719
if (!is_absolute_path(parent->base.path))
720
chdir_notify_register(NULL, odb_source_packed_reparent, packed);
odb/source-packed.h
-6
@@ -90,10 +90,4 @@ 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
-
93
#endif
packfile.c
-16
@@ -1892,22 +1892,6 @@ int packfile_fill_entry(struct packed_git *p,
1892
return 1;
1893
}
1894
1895
-int packfile_store_freshen_object(struct odb_source_packed *store,
1896
- const struct object_id *oid)
1897
-{
1898
- struct pack_entry e;
1899
- if (!find_pack_entry(store, oid, &e))
1900
- return 0;
1901
- if (e.p->is_cruft)
1902
- return 0;
1903
- if (e.p->freshened)
1904
- return 1;
1905
- if (utime(e.p->pack_name, NULL))
1906
- return 0;
1907
- e.p->freshened = 1;
1908
- return 1;
1909
-}
1910
-
1895
static void maybe_invalidate_kept_pack_cache(struct odb_source_packed *store,
1896
unsigned flags)
1897
{
packfile.h
-3
@@ -132,9 +132,6 @@ static inline void repo_for_each_pack_data_next(struct repo_for_each_pack_data *
132
struct packed_git *packfile_store_load_pack(struct odb_source_packed *store,
133
const char *idx_path, int local);
134
135
-int packfile_store_freshen_object(struct odb_source_packed *store,
136
- const struct object_id *oid);
137
-
135
enum kept_pack_type {
136
KEPT_PACK_ON_DISK = (1 << 0),
137
KEPT_PACK_IN_CORE = (1 << 1),