Skip to content

Commit fa13080

Browse files
bk2204gitster
authored andcommitted
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>
1 parent 7b5e614 commit fa13080

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

pack-revindex.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,14 @@ static void create_pack_revindex(struct packed_git *p)
122122
unsigned num_ent = p->num_objects;
123123
unsigned i;
124124
const char *index = p->index_data;
125+
const unsigned hashsz = the_hash_algo->rawsz;
125126

126127
ALLOC_ARRAY(p->revindex, num_ent + 1);
127128
index += 4 * 256;
128129

129130
if (p->index_version > 1) {
130131
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));
132133
const uint32_t *off_64 = off_32 + p->num_objects;
133134
for (i = 0; i < num_ent; i++) {
134135
uint32_t off = ntohl(*off_32++);
@@ -142,16 +143,17 @@ static void create_pack_revindex(struct packed_git *p)
142143
}
143144
} else {
144145
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));
146147
p->revindex[i].offset = ntohl(hl);
147148
p->revindex[i].nr = i;
148149
}
149150
}
150151

151-
/* This knows the pack format -- the 20-byte trailer
152+
/*
153+
* This knows the pack format -- the hash trailer
152154
* follows immediately after the last object data.
153155
*/
154-
p->revindex[num_ent].offset = p->pack_size - 20;
156+
p->revindex[num_ent].offset = p->pack_size - hashsz;
155157
p->revindex[num_ent].nr = -1;
156158
sort_revindex(p->revindex, num_ent, p->pack_size);
157159
}

0 commit comments

Comments
 (0)