]> git.ipfire.org Git - thirdparty/git.git/blobdiff - pack-bitmap.c
cmake: handle also unit tests
[thirdparty/git.git] / pack-bitmap.c
index e0fad723bf380f4d39a9ae123b51f146f77874d4..999f962602da7d1aae2e90cb620c0ffb42a7f510 100644 (file)
@@ -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;
+}