4 static const char show_index_usage
[] =
5 "git show-index < <packed archive index>";
7 int main(int argc
, 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];
51 } *entries
= malloc(nr
* sizeof(entries
[0]));
52 for (i
= 0; i
< nr
; i
++)
53 if (fread(entries
[i
].sha1
, 20, 1, stdin
) != 1)
54 die("unable to read sha1 %u/%u", i
, nr
);
55 for (i
= 0; i
< nr
; i
++)
56 if (fread(&entries
[i
].crc
, 4, 1, stdin
) != 1)
57 die("unable to read crc %u/%u", i
, nr
);
58 for (i
= 0; i
< nr
; i
++)
59 if (fread(&entries
[i
].off
, 4, 1, stdin
) != 1)
60 die("unable to read 32b offset %u/%u", i
, nr
);
61 for (i
= 0; i
< nr
; i
++) {
63 uint32_t off
= ntohl(entries
[i
].off
);
64 if (!(off
& 0x80000000)) {
68 if ((off
& 0x7fffffff) != off64_nr
)
69 die("inconsistent 64b offset index");
70 if (fread(off64
, 8, 1, stdin
) != 1)
71 die("unable to read 64b offset %u", off64_nr
);
72 offset
= (((uint64_t)ntohl(off64
[0])) << 32) |
76 printf("%" PRIuMAX
" %s (%08"PRIx32
")\n",
78 sha1_to_hex(entries
[i
].sha1
),
79 ntohl(entries
[i
].crc
));