pack-bitmap: introduce function to open bitmap for a single source

The function `prepare_bitmap_git()` opens the first bitmap it can find in any of the object sources connected to the repository. In a subsequent commit, the "packed" object database backend will learn to use bitmaps to answer object filters when enumerating objects. That backend operates on a single object source though, so using a bitmap that potentially belongs to a different source would be wrong: - The source would yield objects that are not part of the source itself. - The object source info would be attributed to the wrong source. - With multiple sources, each source would enumerate the same bitmap another time. Introduce a new function `prepare_bitmap_git_for_source()` that only opens bitmaps belonging to the given object source. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Jul 15, 2026 at 08:22 UTC 8cd7ee7b0d12fce9449ea08fe394e18dc97fe059
2 files changed +14
pack-bitmap.c
+12
@@ -753,6 +753,18 @@ struct bitmap_index *prepare_midx_bitmap_git(struct multi_pack_index *midx)
753 return NULL;
754 }
755
756 +struct bitmap_index *prepare_bitmap_git_for_source(struct odb_source_packed *source)
757 +{
758 + struct bitmap_index *bitmap_git = xcalloc(1, sizeof(*bitmap_git));
759 +
760 + if (!open_bitmap_for_source(source, bitmap_git) &&
761 + !load_bitmap(source->base.odb->repo, bitmap_git, 0))
762 + return bitmap_git;
763 +
764 + free_bitmap_index(bitmap_git);
765 + return NULL;
766 +}
767 +
768 int bitmap_index_contains_pack(struct bitmap_index *bitmap, struct packed_git *pack)
769 {
770 for (; bitmap; bitmap = bitmap->base) {
pack-bitmap.h
+2
@@ -9,6 +9,7 @@
9 #include "string-list.h"
10
11 struct commit;
12 +struct odb_source_packed;
13 struct repository;
14 struct rev_info;
15
@@ -68,6 +69,7 @@ struct bitmapped_pack {
69
70 struct bitmap_index *prepare_bitmap_git(struct repository *r);
71 struct bitmap_index *prepare_midx_bitmap_git(struct multi_pack_index *midx);
72 +struct bitmap_index *prepare_bitmap_git_for_source(struct odb_source_packed *source);
73
74 /*
75 * Given a bitmap index, determine whether it contains the pack either directly