4 #include "repository.h"
5 #include "object-store-ll.h"
6 #include "pack-bitmap.h"
11 static int read_midx_file(const char *object_dir
, int show_objects
)
14 struct multi_pack_index
*m
;
16 setup_git_directory();
17 m
= load_multi_pack_index(object_dir
, 1);
22 printf("header: %08x %d %d %d %d\n",
31 if (m
->chunk_pack_names
)
32 printf(" pack-names");
33 if (m
->chunk_oid_fanout
)
34 printf(" oid-fanout");
35 if (m
->chunk_oid_lookup
)
36 printf(" oid-lookup");
37 if (m
->chunk_object_offsets
)
38 printf(" object-offsets");
39 if (m
->chunk_large_offsets
)
40 printf(" large-offsets");
42 printf("\nnum_objects: %d\n", m
->num_objects
);
45 for (i
= 0; i
< m
->num_packs
; i
++)
46 printf("%s\n", m
->pack_names
[i
]);
48 printf("object-dir: %s\n", m
->object_dir
);
54 for (i
= 0; i
< m
->num_objects
; i
++) {
55 nth_midxed_object_oid(&oid
, m
, i
);
56 fill_midx_entry(the_repository
, &oid
, &e
, m
);
58 printf("%s %"PRIu64
"\t%s\n",
59 oid_to_hex(&oid
), e
.offset
, e
.p
->pack_name
);
68 static int read_midx_checksum(const char *object_dir
)
70 struct multi_pack_index
*m
;
72 setup_git_directory();
73 m
= load_multi_pack_index(object_dir
, 1);
76 printf("%s\n", hash_to_hex(get_midx_checksum(m
)));
80 static int read_midx_preferred_pack(const char *object_dir
)
82 struct multi_pack_index
*midx
= NULL
;
83 uint32_t preferred_pack
;
85 setup_git_directory();
87 midx
= load_multi_pack_index(object_dir
, 1);
91 if (midx_preferred_pack(midx
, &preferred_pack
) < 0) {
92 warning(_("could not determine MIDX preferred pack"));
96 printf("%s\n", midx
->pack_names
[preferred_pack
]);
100 static int read_midx_bitmapped_packs(const char *object_dir
)
102 struct multi_pack_index
*midx
= NULL
;
103 struct bitmapped_pack pack
;
106 setup_git_directory();
108 midx
= load_multi_pack_index(object_dir
, 1);
112 for (i
= 0; i
< midx
->num_packs
; i
++) {
113 if (nth_bitmapped_pack(the_repository
, midx
, &pack
, i
) < 0)
116 printf("%s\n", pack_basename(pack
.p
));
117 printf(" bitmap_pos: %"PRIuMAX
"\n", (uintmax_t)pack
.bitmap_pos
);
118 printf(" bitmap_nr: %"PRIuMAX
"\n", (uintmax_t)pack
.bitmap_nr
);
126 int cmd__read_midx(int argc
, const char **argv
)
128 if (!(argc
== 2 || argc
== 3))
129 usage("read-midx [--show-objects|--checksum|--preferred-pack|--bitmap] <object-dir>");
131 if (!strcmp(argv
[1], "--show-objects"))
132 return read_midx_file(argv
[2], 1);
133 else if (!strcmp(argv
[1], "--checksum"))
134 return read_midx_checksum(argv
[2]);
135 else if (!strcmp(argv
[1], "--preferred-pack"))
136 return read_midx_preferred_pack(argv
[2]);
137 else if (!strcmp(argv
[1], "--bitmap"))
138 return read_midx_bitmapped_packs(argv
[2]);
139 return read_midx_file(argv
[1], 0);