]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t/helper/test-read-midx.c: add --checksum mode
authorTaylor Blau <me@ttaylorr.com>
Tue, 31 Aug 2021 20:52:28 +0000 (16:52 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 1 Sep 2021 20:56:43 +0000 (13:56 -0700)
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>
t/helper/test-read-midx.c
t/lib-bitmap.sh

index 7c2eb11a8e70ffe1ff6d438efe0e0f0024caa546..cb0d27049a07e1dcd886bbe6aaede26176a54ee2 100644 (file)
@@ -60,12 +60,26 @@ static int read_midx_file(const char *object_dir, int show_objects)
        return 0;
 }
 
+static int read_midx_checksum(const char *object_dir)
+{
+       struct multi_pack_index *m;
+
+       setup_git_directory();
+       m = load_multi_pack_index(object_dir, 1);
+       if (!m)
+               return 1;
+       printf("%s\n", hash_to_hex(get_midx_checksum(m)));
+       return 0;
+}
+
 int cmd__read_midx(int argc, const char **argv)
 {
        if (!(argc == 2 || argc == 3))
-               usage("read-midx [--show-objects] <object-dir>");
+               usage("read-midx [--show-objects|--checksum] <object-dir>");
 
        if (!strcmp(argv[1], "--show-objects"))
                return read_midx_file(argv[2], 1);
+       else if (!strcmp(argv[1], "--checksum"))
+               return read_midx_checksum(argv[2]);
        return read_midx_file(argv[1], 0);
 }
index 77464da6fd08ad6b226fce9bafc75aac9363c055..21d0392ddac5a2e21f8ce090d87efc6cda4e4d9a 100644 (file)
@@ -260,3 +260,7 @@ have_delta () {
        echo $1 | git cat-file --batch-check="%(deltabase)" >actual &&
        test_cmp expect actual
 }
+
+midx_checksum () {
+       test-tool read-midx --checksum "$1"
+}