@@ -200,6 +200,11 @@ static int release_snapshot(struct snapshot *snapshot)
200200 }
201201}
202202
203+ static size_t snapshot_hexsz (const struct snapshot * snapshot )
204+ {
205+ return snapshot -> refs -> base .repo -> hash_algo -> hexsz ;
206+ }
207+
203208struct ref_store * packed_ref_store_init (struct repository * repo ,
204209 const char * gitdir ,
205210 unsigned int store_flags )
@@ -289,11 +294,13 @@ struct snapshot_record {
289294 size_t len ;
290295};
291296
292- static int cmp_packed_ref_records (const void * v1 , const void * v2 )
297+ static int cmp_packed_ref_records (const void * v1 , const void * v2 ,
298+ void * cb_data )
293299{
300+ const struct snapshot * snapshot = cb_data ;
294301 const struct snapshot_record * e1 = v1 , * e2 = v2 ;
295- const char * r1 = e1 -> start + the_hash_algo -> hexsz + 1 ;
296- const char * r2 = e2 -> start + the_hash_algo -> hexsz + 1 ;
302+ const char * r1 = e1 -> start + snapshot_hexsz ( snapshot ) + 1 ;
303+ const char * r2 = e2 -> start + snapshot_hexsz ( snapshot ) + 1 ;
297304
298305 while (1 ) {
299306 if (* r1 == '\n' )
@@ -314,9 +321,9 @@ static int cmp_packed_ref_records(const void *v1, const void *v2)
314321 * refname.
315322 */
316323static int cmp_record_to_refname (const char * rec , const char * refname ,
317- int start )
324+ int start , const struct snapshot * snapshot )
318325{
319- const char * r1 = rec + the_hash_algo -> hexsz + 1 ;
326+ const char * r1 = rec + snapshot_hexsz ( snapshot ) + 1 ;
320327 const char * r2 = refname ;
321328
322329 while (1 ) {
@@ -363,7 +370,7 @@ static void sort_snapshot(struct snapshot *snapshot)
363370 if (!eol )
364371 /* The safety check should prevent this. */
365372 BUG ("unterminated line found in packed-refs" );
366- if (eol - pos < the_hash_algo -> hexsz + 2 )
373+ if (eol - pos < snapshot_hexsz ( snapshot ) + 2 )
367374 die_invalid_line (snapshot -> refs -> path ,
368375 pos , eof - pos );
369376 eol ++ ;
@@ -389,7 +396,7 @@ static void sort_snapshot(struct snapshot *snapshot)
389396 if (sorted &&
390397 nr > 1 &&
391398 cmp_packed_ref_records (& records [nr - 2 ],
392- & records [nr - 1 ]) >= 0 )
399+ & records [nr - 1 ], snapshot ) >= 0 )
393400 sorted = 0 ;
394401
395402 pos = eol ;
@@ -399,7 +406,7 @@ static void sort_snapshot(struct snapshot *snapshot)
399406 goto cleanup ;
400407
401408 /* We need to sort the memory. First we sort the records array: */
402- QSORT (records , nr , cmp_packed_ref_records );
409+ QSORT_S (records , nr , cmp_packed_ref_records , snapshot );
403410
404411 /*
405412 * Allocate a new chunk of memory, and copy the old memory to
@@ -475,7 +482,8 @@ static void verify_buffer_safe(struct snapshot *snapshot)
475482 return ;
476483
477484 last_line = find_start_of_record (start , eof - 1 );
478- if (* (eof - 1 ) != '\n' || eof - last_line < the_hash_algo -> hexsz + 2 )
485+ if (* (eof - 1 ) != '\n' ||
486+ eof - last_line < snapshot_hexsz (snapshot ) + 2 )
479487 die_invalid_line (snapshot -> refs -> path ,
480488 last_line , eof - last_line );
481489}
@@ -570,7 +578,7 @@ static const char *find_reference_location_1(struct snapshot *snapshot,
570578
571579 mid = lo + (hi - lo ) / 2 ;
572580 rec = find_start_of_record (lo , mid );
573- cmp = cmp_record_to_refname (rec , refname , start );
581+ cmp = cmp_record_to_refname (rec , refname , start , snapshot );
574582 if (cmp < 0 ) {
575583 lo = find_end_of_record (mid , hi );
576584 } else if (cmp > 0 ) {
@@ -867,7 +875,7 @@ static int next_record(struct packed_ref_iterator *iter)
867875 iter -> base .flags = REF_ISPACKED ;
868876 p = iter -> pos ;
869877
870- if (iter -> eof - p < the_hash_algo -> hexsz + 2 ||
878+ if (iter -> eof - p < snapshot_hexsz ( iter -> snapshot ) + 2 ||
871879 parse_oid_hex (p , & iter -> oid , & p ) ||
872880 !isspace (* p ++ ))
873881 die_invalid_line (iter -> snapshot -> refs -> path ,
@@ -897,7 +905,7 @@ static int next_record(struct packed_ref_iterator *iter)
897905
898906 if (iter -> pos < iter -> eof && * iter -> pos == '^' ) {
899907 p = iter -> pos + 1 ;
900- if (iter -> eof - p < the_hash_algo -> hexsz + 1 ||
908+ if (iter -> eof - p < snapshot_hexsz ( iter -> snapshot ) + 1 ||
901909 parse_oid_hex (p , & iter -> peeled , & p ) ||
902910 * p ++ != '\n' )
903911 die_invalid_line (iter -> snapshot -> refs -> path ,
0 commit comments