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>
brian m. carlson committed
May 2, 2018 at 00:25 UTC
00de60633228f11a2941c25fc7738f8028756cb9
1 file changed
+7
-5
builtin/pack-redundant.c
+7
-5
@@ -252,13 +252,14 @@ static void cmp_two_packs(struct pack_list *p1, struct pack_list *p2)
252
unsigned long p1_off = 0, p2_off = 0, p1_step, p2_step;
253
const unsigned char *p1_base, *p2_base;
254
struct llist_item *p1_hint = NULL, *p2_hint = NULL;
255
+ const unsigned int hashsz = the_hash_algo->rawsz;
256
257
p1_base = p1->pack->index_data;
258
p2_base = p2->pack->index_data;
259
p1_base += 256 * 4 + ((p1->pack->index_version < 2) ? 4 : 8);
260
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);
263
264
while (p1_off < p1->pack->num_objects * p1_step &&
265
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)
360
size_t ret = 0;
361
unsigned long p1_off = 0, p2_off = 0, p1_step, p2_step;
362
const unsigned char *p1_base, *p2_base;
363
+ const unsigned int hashsz = the_hash_algo->rawsz;
364
365
p1_base = p1->index_data;
366
p2_base = p2->index_data;
367
p1_base += 256 * 4 + ((p1->index_version < 2) ? 4 : 8);
368
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);
371
372
while (p1_off < p1->num_objects * p1_step &&
373
p2_off < p2->num_objects * p2_step)
@@ -558,7 +560,7 @@ static struct pack_list * add_pack(struct packed_git *p)
560
561
base = p->index_data;
562
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);
564
while (off < p->num_objects * step) {
565
llist_insert_back(l.all_objects, base + off);
566
off += step;