pack-revindex: express constants in terms of the_hash_algo
Express the various constants used in terms of the_hash_algo. While we're at it, fix a comment style issue as well. Reviewed-by: Stefan Beller <sbeller@google.com> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Oct 15, 2018 at 00:01 UTC
fa130802d9ccde50e4097b2b1c5324990be3ffb4
1 file changed
+6
-4
pack-revindex.c
+6
-4
@@ -122,13 +122,14 @@ static void create_pack_revindex(struct packed_git *p)
122
unsigned num_ent = p->num_objects;
123
unsigned i;
124
const char *index = p->index_data;
125
+ const unsigned hashsz = the_hash_algo->rawsz;
126
127
ALLOC_ARRAY(p->revindex, num_ent + 1);
128
index += 4 * 256;
129
130
if (p->index_version > 1) {
131
const uint32_t *off_32 =
131
- (uint32_t *)(index + 8 + p->num_objects * (20 + 4));
132
+ (uint32_t *)(index + 8 + p->num_objects * (hashsz + 4));
133
const uint32_t *off_64 = off_32 + p->num_objects;
134
for (i = 0; i < num_ent; i++) {
135
uint32_t off = ntohl(*off_32++);
@@ -142,16 +143,17 @@ static void create_pack_revindex(struct packed_git *p)
143
}
144
} else {
145
for (i = 0; i < num_ent; i++) {
145
- uint32_t hl = *((uint32_t *)(index + 24 * i));
146
+ uint32_t hl = *((uint32_t *)(index + (hashsz + 4) * i));
147
p->revindex[i].offset = ntohl(hl);
148
p->revindex[i].nr = i;
149
}
150
}
151
151
- /* This knows the pack format -- the 20-byte trailer
152
+ /*
153
+ * This knows the pack format -- the hash trailer
154
* follows immediately after the last object data.
155
*/
154
- p->revindex[num_ent].offset = p->pack_size - 20;
156
+ p->revindex[num_ent].offset = p->pack_size - hashsz;
157
p->revindex[num_ent].nr = -1;
158
sort_revindex(p->revindex, num_ent, p->pack_size);
159
}