t/helper/test-read-midx.c: add --checksum mode
Subsequent tests will want to check for the existence of a multi-pack bitmap which matches the multi-pack-index stored in the pack directory. The multi-pack bitmap includes the hex checksum of the MIDX it corresponds to in its filename (for example, '$packdir/multi-pack-index-<checksum>.bitmap'). As a result, some tests want a way to learn what '<checksum>' is. This helper addresses that need by printing the checksum of the repository's multi-pack-index. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Taylor Blau committed
Aug 31, 2021 at 16:52 UTC
b1b82d1c3006ff9e25873d4ff01f976a13b526bb
2 files changed
+19
-1
t/helper/test-read-midx.c
+15
-1
@@ -60,12 +60,26 @@ static int read_midx_file(const char *object_dir, int show_objects)
60
return 0;
61
}
62
63
+static int read_midx_checksum(const char *object_dir)
64
+{
65
+ struct multi_pack_index *m;
66
+
67
+ setup_git_directory();
68
+ m = load_multi_pack_index(object_dir, 1);
69
+ if (!m)
70
+ return 1;
71
+ printf("%s\n", hash_to_hex(get_midx_checksum(m)));
72
+ return 0;
73
+}
74
+
75
int cmd__read_midx(int argc, const char **argv)
76
{
77
if (!(argc == 2 || argc == 3))
66
- usage("read-midx [--show-objects] <object-dir>");
78
+ usage("read-midx [--show-objects|--checksum] <object-dir>");
79
80
if (!strcmp(argv[1], "--show-objects"))
81
return read_midx_file(argv[2], 1);
82
+ else if (!strcmp(argv[1], "--checksum"))
83
+ return read_midx_checksum(argv[2]);
84
return read_midx_file(argv[1], 0);
85
}
t/lib-bitmap.sh
+4
@@ -260,3 +260,7 @@ have_delta () {
260
echo $1 | git cat-file --batch-check="%(deltabase)" >actual &&
261
test_cmp expect actual
262
}
263
+
264
+midx_checksum () {
265
+ test-tool read-midx --checksum "$1"
266
+}