show-index: switch hard-coded constants to the_hash_algo
show-index uses a variety of hard-coded constants to enumerate the values in pack indices. Switch these hard-coded constants to use the_hash_algo or GIT_MAX_RAWSZ, as appropriate, and convert one instance of an unsigned char array to struct object_id. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Aug 18, 2019 at 20:04 UTC
7962e046ff2bfdeab1dad5c969dbd2b9209efe2f
1 file changed
+6
-5
builtin/show-index.c
+6
-5
@@ -11,6 +11,7 @@ int cmd_show_index(int argc, const char **argv, const char *prefix)
11
unsigned nr;
12
unsigned int version;
13
static unsigned int top_index[256];
14
+ const unsigned hashsz = the_hash_algo->rawsz;
15
16
if (argc != 1)
17
usage(show_index_usage);
@@ -36,9 +37,9 @@ int cmd_show_index(int argc, const char **argv, const char *prefix)
37
}
38
if (version == 1) {
39
for (i = 0; i < nr; i++) {
39
- unsigned int offset, entry[6];
40
+ unsigned int offset, entry[(GIT_MAX_RAWSZ + 4) / sizeof(unsigned int)];
41
41
- if (fread(entry, 4 + 20, 1, stdin) != 1)
42
+ if (fread(entry, 4 + hashsz, 1, stdin) != 1)
43
die("unable to read entry %u/%u", i, nr);
44
offset = ntohl(entry[0]);
45
printf("%u %s\n", offset, sha1_to_hex((void *)(entry+1)));
@@ -46,13 +47,13 @@ int cmd_show_index(int argc, const char **argv, const char *prefix)
47
} else {
48
unsigned off64_nr = 0;
49
struct {
49
- unsigned char sha1[20];
50
+ struct object_id oid;
51
uint32_t crc;
52
uint32_t off;
53
} *entries;
54
ALLOC_ARRAY(entries, nr);
55
for (i = 0; i < nr; i++)
55
- if (fread(entries[i].sha1, 20, 1, stdin) != 1)
56
+ if (fread(entries[i].oid.hash, hashsz, 1, stdin) != 1)
57
die("unable to read sha1 %u/%u", i, nr);
58
for (i = 0; i < nr; i++)
59
if (fread(&entries[i].crc, 4, 1, stdin) != 1)
@@ -77,7 +78,7 @@ int cmd_show_index(int argc, const char **argv, const char *prefix)
78
}
79
printf("%" PRIuMAX " %s (%08"PRIx32")\n",
80
(uintmax_t) offset,
80
- sha1_to_hex(entries[i].sha1),
81
+ oid_to_hex(&entries[i].oid),
82
ntohl(entries[i].crc));
83
}
84
free(entries);