odb/source-packed: wire up `close()` callback

Wire up a new `close()` callback for the packed source and call it from the "files" source via the generic `odb_source_close()` interface. 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 4f35c8b060085835150ab605207f6669e58a8d94
4 files changed +17 -19
odb/source-files.c
+1 -1
@@ -38,7 +38,7 @@ static void odb_source_files_close(struct odb_source *source)
38 {
39 struct odb_source_files *files = odb_source_files_downcast(source);
40 odb_source_close(&files->loose->base);
41 - packfile_store_close(files->packed);
41 + odb_source_close(&files->packed->base);
42 }
43
44 static void odb_source_files_reprepare(struct odb_source *source)
odb/source-packed.c
+16
@@ -1,6 +1,7 @@
1 #include "git-compat-util.h"
2 #include "abspath.h"
3 #include "chdir-notify.h"
4 +#include "midx.h"
5 #include "odb/source-packed.h"
6 #include "packfile.h"
7
@@ -16,6 +17,20 @@ static void odb_source_packed_reparent(const char *name UNUSED,
17 packed->base.path = path;
18 }
19
20 +static void odb_source_packed_close(struct odb_source *source)
21 +{
22 + struct odb_source_packed *packed = odb_source_packed_downcast(source);
23 +
24 + for (struct packfile_list_entry *e = packed->packs.head; e; e = e->next) {
25 + if (e->pack->do_not_close)
26 + BUG("want to close pack marked 'do-not-close'");
27 + close_pack(e->pack);
28 + }
29 + if (packed->midx)
30 + close_midx(packed->midx);
31 + packed->midx = NULL;
32 +}
33 +
34 static void odb_source_packed_free(struct odb_source *source)
35 {
36 struct odb_source_packed *packed = odb_source_packed_downcast(source);
@@ -42,6 +57,7 @@ struct odb_source_packed *odb_source_packed_new(struct odb_source_files *parent)
57 strmap_init(&packed->packs_by_path);
58
59 packed->base.free = odb_source_packed_free;
60 + packed->base.close = odb_source_packed_close;
61
62 if (!is_absolute_path(parent->base.path))
63 chdir_notify_register(NULL, odb_source_packed_reparent, packed);
packfile.c
-12
@@ -2749,18 +2749,6 @@ int parse_pack_header_option(const char *in, unsigned char *out, unsigned int *l
2749 return 0;
2750 }
2751
2752 -void packfile_store_close(struct odb_source_packed *store)
2753 -{
2754 - for (struct packfile_list_entry *e = store->packs.head; e; e = e->next) {
2755 - if (e->pack->do_not_close)
2756 - BUG("want to close pack marked 'do-not-close'");
2757 - close_pack(e->pack);
2758 - }
2759 - if (store->midx)
2760 - close_midx(store->midx);
2761 - store->midx = NULL;
2762 -}
2763 -
2752 struct odb_packed_read_stream {
2753 struct odb_read_stream base;
2754 struct packed_git *pack;
packfile.h
-6
@@ -55,12 +55,6 @@ struct packed_git {
55 char pack_name[FLEX_ARRAY]; /* more */
56 };
57
58 -/*
59 - * Close all packfiles associated with this store. The packfiles won't be
60 - * free'd, so they can be re-opened at a later point in time.
61 - */
62 -void packfile_store_close(struct odb_source_packed *store);
63 -
58 /*
59 * Prepare the packfile store by loading packfiles and multi-pack indices for
60 * all alternates. This becomes a no-op if the store is already prepared.