]> git.ipfire.org Git - thirdparty/git.git/blame - t/helper/test-read-midx.c
Merge branch 'en/ort-perf-batch-9'
[thirdparty/git.git] / t / helper / test-read-midx.c
CommitLineData
4d80560c
DS
1#include "test-tool.h"
2#include "cache.h"
3#include "midx.h"
4#include "repository.h"
5#include "object-store.h"
6
86d174b7 7static int read_midx_file(const char *object_dir, int show_objects)
4d80560c 8{
3227565c 9 uint32_t i;
d9607542
DS
10 struct multi_pack_index *m;
11
12 setup_git_directory();
13 m = load_multi_pack_index(object_dir, 1);
4d80560c
DS
14
15 if (!m)
16 return 1;
17
d9607542 18 printf("header: %08x %d %d %d %d\n",
4d80560c
DS
19 m->signature,
20 m->version,
d9607542 21 m->hash_len,
4d80560c
DS
22 m->num_chunks,
23 m->num_packs);
24
32f3c541
DS
25 printf("chunks:");
26
27 if (m->chunk_pack_names)
28 printf(" pack-names");
d7cacf29
DS
29 if (m->chunk_oid_fanout)
30 printf(" oid-fanout");
0d5b3a5e
DS
31 if (m->chunk_oid_lookup)
32 printf(" oid-lookup");
662148c4
DS
33 if (m->chunk_object_offsets)
34 printf(" object-offsets");
35 if (m->chunk_large_offsets)
36 printf(" large-offsets");
32f3c541 37
d7cacf29 38 printf("\nnum_objects: %d\n", m->num_objects);
32f3c541 39
3227565c
DS
40 printf("packs:\n");
41 for (i = 0; i < m->num_packs; i++)
42 printf("%s\n", m->pack_names[i]);
43
4d80560c
DS
44 printf("object-dir: %s\n", m->object_dir);
45
86d174b7
TB
46 if (show_objects) {
47 struct object_id oid;
48 struct pack_entry e;
49
50 for (i = 0; i < m->num_objects; i++) {
51 nth_midxed_object_oid(&oid, m, i);
52 fill_midx_entry(the_repository, &oid, &e, m);
53
54 printf("%s %"PRIu64"\t%s\n",
55 oid_to_hex(&oid), e.offset, e.p->pack_name);
56 }
57 return 0;
58 }
59
4d80560c
DS
60 return 0;
61}
62
63int cmd__read_midx(int argc, const char **argv)
64{
86d174b7
TB
65 if (!(argc == 2 || argc == 3))
66 usage("read-midx [--show-objects] <object-dir>");
4d80560c 67
86d174b7
TB
68 if (!strcmp(argv[1], "--show-objects"))
69 return read_midx_file(argv[2], 1);
70 return read_midx_file(argv[1], 0);
4d80560c 71}