@@ -200,6 +200,11 @@ static int release_snapshot(struct snapshot *snapshot)
200
200
}
201
201
}
202
202
203
+ static size_t snapshot_hexsz (const struct snapshot * snapshot )
204
+ {
205
+ return snapshot -> refs -> base .repo -> hash_algo -> hexsz ;
206
+ }
207
+
203
208
struct ref_store * packed_ref_store_init (struct repository * repo ,
204
209
const char * gitdir ,
205
210
unsigned int store_flags )
@@ -289,11 +294,13 @@ struct snapshot_record {
289
294
size_t len ;
290
295
};
291
296
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 )
293
299
{
300
+ const struct snapshot * snapshot = cb_data ;
294
301
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 ;
297
304
298
305
while (1 ) {
299
306
if (* r1 == '\n' )
@@ -314,9 +321,9 @@ static int cmp_packed_ref_records(const void *v1, const void *v2)
314
321
* refname.
315
322
*/
316
323
static int cmp_record_to_refname (const char * rec , const char * refname ,
317
- int start )
324
+ int start , const struct snapshot * snapshot )
318
325
{
319
- const char * r1 = rec + the_hash_algo -> hexsz + 1 ;
326
+ const char * r1 = rec + snapshot_hexsz ( snapshot ) + 1 ;
320
327
const char * r2 = refname ;
321
328
322
329
while (1 ) {
@@ -363,7 +370,7 @@ static void sort_snapshot(struct snapshot *snapshot)
363
370
if (!eol )
364
371
/* The safety check should prevent this. */
365
372
BUG ("unterminated line found in packed-refs" );
366
- if (eol - pos < the_hash_algo -> hexsz + 2 )
373
+ if (eol - pos < snapshot_hexsz ( snapshot ) + 2 )
367
374
die_invalid_line (snapshot -> refs -> path ,
368
375
pos , eof - pos );
369
376
eol ++ ;
@@ -389,7 +396,7 @@ static void sort_snapshot(struct snapshot *snapshot)
389
396
if (sorted &&
390
397
nr > 1 &&
391
398
cmp_packed_ref_records (& records [nr - 2 ],
392
- & records [nr - 1 ]) >= 0 )
399
+ & records [nr - 1 ], snapshot ) >= 0 )
393
400
sorted = 0 ;
394
401
395
402
pos = eol ;
@@ -399,7 +406,7 @@ static void sort_snapshot(struct snapshot *snapshot)
399
406
goto cleanup ;
400
407
401
408
/* 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 );
403
410
404
411
/*
405
412
* Allocate a new chunk of memory, and copy the old memory to
@@ -475,7 +482,8 @@ static void verify_buffer_safe(struct snapshot *snapshot)
475
482
return ;
476
483
477
484
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 )
479
487
die_invalid_line (snapshot -> refs -> path ,
480
488
last_line , eof - last_line );
481
489
}
@@ -570,7 +578,7 @@ static const char *find_reference_location_1(struct snapshot *snapshot,
570
578
571
579
mid = lo + (hi - lo ) / 2 ;
572
580
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 );
574
582
if (cmp < 0 ) {
575
583
lo = find_end_of_record (mid , hi );
576
584
} else if (cmp > 0 ) {
@@ -867,7 +875,7 @@ static int next_record(struct packed_ref_iterator *iter)
867
875
iter -> base .flags = REF_ISPACKED ;
868
876
p = iter -> pos ;
869
877
870
- if (iter -> eof - p < the_hash_algo -> hexsz + 2 ||
878
+ if (iter -> eof - p < snapshot_hexsz ( iter -> snapshot ) + 2 ||
871
879
parse_oid_hex (p , & iter -> oid , & p ) ||
872
880
!isspace (* p ++ ))
873
881
die_invalid_line (iter -> snapshot -> refs -> path ,
@@ -897,7 +905,7 @@ static int next_record(struct packed_ref_iterator *iter)
897
905
898
906
if (iter -> pos < iter -> eof && * iter -> pos == '^' ) {
899
907
p = iter -> pos + 1 ;
900
- if (iter -> eof - p < the_hash_algo -> hexsz + 1 ||
908
+ if (iter -> eof - p < snapshot_hexsz ( iter -> snapshot ) + 1 ||
901
909
parse_oid_hex (p , & iter -> peeled , & p ) ||
902
910
* p ++ != '\n' )
903
911
die_invalid_line (iter -> snapshot -> refs -> path ,
0 commit comments