builtin/fsck: move bitmap verification into the packed source

The checks for bitmaps live in `verify_bitmap_files()`, which is called
by "builtin/fsck.c". These checks are obviously specific to the "packed"
backend.

Move the logic into `odb_source_packed_fsck()`. As in preceding commits,
this means that we now properly honor both "--connectivity-only" and
"--no-full". Furthermore, we drop the dedicated `ERROR_BITMAP` bit and
instead use the generic `ERROR_OBJECT` bit.

Note that this change also adapts `verify_bitmap_files()` to be
focused on a single "packed" source instead of verifying bitmaps from
all sources. This change is required as we already know to loop around
the sources in `odb_fsck()` itself.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt authored and Junio C Hamano committed 2026-09-11 09:14:44 -07:00
1 parent 426d291b60
commit 1bbb92d540
5 files changed
+23 -23

No files matched your search

-5
View File
@@ -23,7 +23,6 @@
#include "run-command.h"
#include "sparse-index.h"
#include "worktree.h"
#include "pack-bitmap.h"
#define REACHABLE 0x0001
#define SEEN 0x0002
@@ -50,7 +49,6 @@ static timestamp_t now;
#define ERROR_REFS 010
#define ERROR_COMMIT_GRAPH 020
#define ERROR_MULTI_PACK_INDEX 040
#define ERROR_BITMAP 0200
static const char *describe_object(const struct object_id *oid)
{
@@ -1068,9 +1066,6 @@ int cmd_fsck(int argc,
free_worktrees(worktrees);
}
if (verify_bitmap_files(repo))
errors_found |= ERROR_BITMAP;
check_connectivity(repo);
if (repo->settings.core_commit_graph) {
+3
View File
@@ -909,6 +909,9 @@ static int odb_source_packed_fsck(struct odb_source *source,
if (verify_reverse_indices(packed, opts) < 0)
ret = -1;
if (verify_bitmap_files(packed))
ret = -1;
return ret;
}
+10 -16
View File
@@ -3410,28 +3410,22 @@ static int verify_bitmap_file(const struct git_hash_algo *algop,
return res;
}
int verify_bitmap_files(struct repository *r)
int verify_bitmap_files(struct odb_source_packed *source)
{
struct odb_source *source;
struct packed_git *p;
struct packfile_list_entry *e;
struct multi_pack_index *m;
int res = 0;
for (source = r->objects->sources; source; source = source->next) {
struct odb_source_files *files = odb_source_files_downcast(source);
struct multi_pack_index *m = get_multi_pack_index(files->packed);
char *midx_bitmap_name;
if (!m)
continue;
midx_bitmap_name = midx_bitmap_filename(m);
res |= verify_bitmap_file(r->hash_algo, midx_bitmap_name);
m = get_multi_pack_index(source);
if (m) {
char *midx_bitmap_name = midx_bitmap_filename(m);
res |= verify_bitmap_file(source->base.odb->repo->hash_algo, midx_bitmap_name);
free(midx_bitmap_name);
}
repo_for_each_pack(r, p) {
char *pack_bitmap_name = pack_bitmap_filename(p);
res |= verify_bitmap_file(r->hash_algo, pack_bitmap_name);
for (e = packfile_store_get_packs(source); e; e = e->next) {
char *pack_bitmap_name = pack_bitmap_filename(e->pack);
res |= verify_bitmap_file(source->base.odb->repo->hash_algo, pack_bitmap_name);
free(pack_bitmap_name);
}
+1 -1
View File
@@ -205,7 +205,7 @@ int bitmap_is_midx(struct bitmap_index *bitmap_git);
int bitmap_is_preferred_refname(struct repository *r, const char *refname);
int verify_bitmap_files(struct repository *r);
int verify_bitmap_files(struct odb_source_packed *source);
struct ewah_bitmap *read_bitmap(const unsigned char *map,
size_t map_size, size_t *map_pos);
+9 -1
View File
@@ -498,7 +498,15 @@ test_expect_success 'git fsck correctly identifies good and bad bitmaps' '
corrupt_file "$packbitmap" &&
test_must_fail git fsck 2>err &&
test_grep "bitmap file '\''$midxbitmap'\'' has invalid checksum" err &&
test_grep "bitmap file '\''$packbitmap'\'' has invalid checksum" err
test_grep "bitmap file '\''$packbitmap'\'' has invalid checksum" err &&
# The bitmap checks are performed with "--no-full", but not with
# "--connectivity-only".
test_must_fail git fsck --no-full 2>err &&
test_grep "bitmap file '\''$midxbitmap'\'' has invalid checksum" err &&
test_grep "bitmap file '\''$packbitmap'\'' has invalid checksum" err &&
git fsck --connectivity-only 2>err &&
test_grep ! "invalid checksum" err
'
test_expect_success 'corrupt MIDX with bitmap causes fallback' '