Skip to content

Commit 00de606

Browse files
bk2204gitster
authored andcommitted
pack-redundant: abstract away hash algorithm
Instead of using hard-coded instances of the constant 20, use the_hash_algo to look up the correct constant. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 4117910 commit 00de606

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

builtin/pack-redundant.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,13 +252,14 @@ static void cmp_two_packs(struct pack_list *p1, struct pack_list *p2)
252252
unsigned long p1_off = 0, p2_off = 0, p1_step, p2_step;
253253
const unsigned char *p1_base, *p2_base;
254254
struct llist_item *p1_hint = NULL, *p2_hint = NULL;
255+
const unsigned int hashsz = the_hash_algo->rawsz;
255256

256257
p1_base = p1->pack->index_data;
257258
p2_base = p2->pack->index_data;
258259
p1_base += 256 * 4 + ((p1->pack->index_version < 2) ? 4 : 8);
259260
p2_base += 256 * 4 + ((p2->pack->index_version < 2) ? 4 : 8);
260-
p1_step = (p1->pack->index_version < 2) ? 24 : 20;
261-
p2_step = (p2->pack->index_version < 2) ? 24 : 20;
261+
p1_step = hashsz + ((p1->pack->index_version < 2) ? 4 : 0);
262+
p2_step = hashsz + ((p2->pack->index_version < 2) ? 4 : 0);
262263

263264
while (p1_off < p1->pack->num_objects * p1_step &&
264265
p2_off < p2->pack->num_objects * p2_step)
@@ -359,13 +360,14 @@ static size_t sizeof_union(struct packed_git *p1, struct packed_git *p2)
359360
size_t ret = 0;
360361
unsigned long p1_off = 0, p2_off = 0, p1_step, p2_step;
361362
const unsigned char *p1_base, *p2_base;
363+
const unsigned int hashsz = the_hash_algo->rawsz;
362364

363365
p1_base = p1->index_data;
364366
p2_base = p2->index_data;
365367
p1_base += 256 * 4 + ((p1->index_version < 2) ? 4 : 8);
366368
p2_base += 256 * 4 + ((p2->index_version < 2) ? 4 : 8);
367-
p1_step = (p1->index_version < 2) ? 24 : 20;
368-
p2_step = (p2->index_version < 2) ? 24 : 20;
369+
p1_step = hashsz + ((p1->index_version < 2) ? 4 : 0);
370+
p2_step = hashsz + ((p2->index_version < 2) ? 4 : 0);
369371

370372
while (p1_off < p1->num_objects * p1_step &&
371373
p2_off < p2->num_objects * p2_step)
@@ -558,7 +560,7 @@ static struct pack_list * add_pack(struct packed_git *p)
558560

559561
base = p->index_data;
560562
base += 256 * 4 + ((p->index_version < 2) ? 4 : 8);
561-
step = (p->index_version < 2) ? 24 : 20;
563+
step = the_hash_algo->rawsz + ((p->index_version < 2) ? 4 : 0);
562564
while (off < p->num_objects * step) {
563565
llist_insert_back(l.all_objects, base + off);
564566
off += step;

0 commit comments

Comments
 (0)