4 static const char show_index_usage
[] =
7 int cmd_main(int argc
, const char **argv
)
12 static unsigned int top_index
[256];
15 usage(show_index_usage
);
16 if (fread(top_index
, 2 * 4, 1, stdin
) != 1)
17 die("unable to read header");
18 if (top_index
[0] == htonl(PACK_IDX_SIGNATURE
)) {
19 version
= ntohl(top_index
[1]);
20 if (version
< 2 || version
> 2)
21 die("unknown index version");
22 if (fread(top_index
, 256 * 4, 1, stdin
) != 1)
23 die("unable to read index");
26 if (fread(&top_index
[2], 254 * 4, 1, stdin
) != 1)
27 die("unable to read index");
30 for (i
= 0; i
< 256; i
++) {
31 unsigned n
= ntohl(top_index
[i
]);
33 die("corrupt index file");
37 for (i
= 0; i
< nr
; i
++) {
38 unsigned int offset
, entry
[6];
40 if (fread(entry
, 4 + 20, 1, stdin
) != 1)
41 die("unable to read entry %u/%u", i
, nr
);
42 offset
= ntohl(entry
[0]);
43 printf("%u %s\n", offset
, sha1_to_hex((void *)(entry
+1)));
46 unsigned off64_nr
= 0;
48 unsigned char sha1
[20];
52 ALLOC_ARRAY(entries
, nr
);
53 for (i
= 0; i
< nr
; i
++)
54 if (fread(entries
[i
].sha1
, 20, 1, stdin
) != 1)
55 die("unable to read sha1 %u/%u", i
, nr
);
56 for (i
= 0; i
< nr
; i
++)
57 if (fread(&entries
[i
].crc
, 4, 1, stdin
) != 1)
58 die("unable to read crc %u/%u", i
, nr
);
59 for (i
= 0; i
< nr
; i
++)
60 if (fread(&entries
[i
].off
, 4, 1, stdin
) != 1)
61 die("unable to read 32b offset %u/%u", i
, nr
);
62 for (i
= 0; i
< nr
; i
++) {
64 uint32_t off
= ntohl(entries
[i
].off
);
65 if (!(off
& 0x80000000)) {
69 if ((off
& 0x7fffffff) != off64_nr
)
70 die("inconsistent 64b offset index");
71 if (fread(off64
, 8, 1, stdin
) != 1)
72 die("unable to read 64b offset %u", off64_nr
);
73 offset
= (((uint64_t)ntohl(off64
[0])) << 32) |
77 printf("%" PRIuMAX
" %s (%08"PRIx32
")\n",
79 sha1_to_hex(entries
[i
].sha1
),
80 ntohl(entries
[i
].crc
));