diff options
| author | Junio C Hamano <gitster@pobox.com> | 2023-05-15 13:59:04 -0700 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2023-05-15 13:59:04 -0700 |
| commit | cd2b740ca95291b81b8e75000d2ee76b4f735877 (patch) | |
| tree | 31bf2437d5454699cdd86e325046e95a476b5ccd /pack-bitmap.c | |
| parent | Merge branch 'js/gitk-fixes-from-gfw' (diff) | |
| parent | fsck: use local repository (diff) | |
| download | git-cd2b740ca95291b81b8e75000d2ee76b4f735877.tar.gz git-cd2b740ca95291b81b8e75000d2ee76b4f735877.zip | |
Merge branch 'ds/fsck-bitmap'
"git fsck" learned to detect bit-flip breakages in the reachability
bitmap files.
* ds/fsck-bitmap:
fsck: use local repository
fsck: verify checksums of all .bitmap files
Diffstat (limited to 'pack-bitmap.c')
| -rw-r--r-- | pack-bitmap.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/pack-bitmap.c b/pack-bitmap.c index e0fad723bf..999f962602 100644 --- a/pack-bitmap.c +++ b/pack-bitmap.c @@ -2346,3 +2346,48 @@ int bitmap_is_preferred_refname(struct repository *r, const char *refname) return 0; } + +static int verify_bitmap_file(const char *name) +{ + struct stat st; + unsigned char *data; + int fd = git_open(name); + int res = 0; + + /* It is OK to not have the file. */ + if (fd < 0 || fstat(fd, &st)) { + if (fd >= 0) + close(fd); + return 0; + } + + data = xmmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + close(fd); + if (!hashfile_checksum_valid(data, st.st_size)) + res = error(_("bitmap file '%s' has invalid checksum"), + name); + + munmap(data, st.st_size); + return res; +} + +int verify_bitmap_files(struct repository *r) +{ + int res = 0; + + for (struct multi_pack_index *m = get_multi_pack_index(r); + m; m = m->next) { + char *midx_bitmap_name = midx_bitmap_filename(m); + res |= verify_bitmap_file(midx_bitmap_name); + free(midx_bitmap_name); + } + + for (struct packed_git *p = get_all_packs(r); + p; p = p->next) { + char *pack_bitmap_name = pack_bitmap_filename(p); + res |= verify_bitmap_file(pack_bitmap_name); + free(pack_bitmap_name); + } + + return res; +} |
