refs/packed: remove references to `the_hash_algo`
Remove references to `the_hash_algo` in favor of the hash algo specified by the repository associated with the packed ref store. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
May 17, 2024 at 10:19 UTC
00892786b83936ec53d7d38df9bfc4e180fc2e19
1 file changed
+20
-12
refs/packed-backend.c
+20
-12
@@ -200,6 +200,11 @@ static int release_snapshot(struct snapshot *snapshot)
200
}
201
}
202
203
+static size_t snapshot_hexsz(const struct snapshot *snapshot)
204
+{
205
+ return snapshot->refs->base.repo->hash_algo->hexsz;
206
+}
207
+
208
struct ref_store *packed_ref_store_init(struct repository *repo,
209
const char *gitdir,
210
unsigned int store_flags)
@@ -289,11 +294,13 @@ struct snapshot_record {
294
size_t len;
295
};
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)
299
{
300
+ const struct snapshot *snapshot = cb_data;
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;
304
305
while (1) {
306
if (*r1 == '\n')
@@ -314,9 +321,9 @@ static int cmp_packed_ref_records(const void *v1, const void *v2)
321
* refname.
322
*/
323
static int cmp_record_to_refname(const char *rec, const char *refname,
317
- int start)
324
+ int start, const struct snapshot *snapshot)
325
{
319
- const char *r1 = rec + the_hash_algo->hexsz + 1;
326
+ const char *r1 = rec + snapshot_hexsz(snapshot) + 1;
327
const char *r2 = refname;
328
329
while (1) {
@@ -363,7 +370,7 @@ static void sort_snapshot(struct snapshot *snapshot)
370
if (!eol)
371
/* The safety check should prevent this. */
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)
374
die_invalid_line(snapshot->refs->path,
375
pos, eof - pos);
376
eol++;
@@ -389,7 +396,7 @@ static void sort_snapshot(struct snapshot *snapshot)
396
if (sorted &&
397
nr > 1 &&
398
cmp_packed_ref_records(&records[nr - 2],
392
- &records[nr - 1]) >= 0)
399
+ &records[nr - 1], snapshot) >= 0)
400
sorted = 0;
401
402
pos = eol;
@@ -399,7 +406,7 @@ static void sort_snapshot(struct snapshot *snapshot)
406
goto cleanup;
407
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);
410
411
/*
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)
482
return;
483
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)
487
die_invalid_line(snapshot->refs->path,
488
last_line, eof - last_line);
489
}
@@ -570,7 +578,7 @@ static const char *find_reference_location_1(struct snapshot *snapshot,
578
579
mid = lo + (hi - lo) / 2;
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);
582
if (cmp < 0) {
583
lo = find_end_of_record(mid, hi);
584
} else if (cmp > 0) {
@@ -867,7 +875,7 @@ static int next_record(struct packed_ref_iterator *iter)
875
iter->base.flags = REF_ISPACKED;
876
p = iter->pos;
877
870
- if (iter->eof - p < the_hash_algo->hexsz + 2 ||
878
+ if (iter->eof - p < snapshot_hexsz(iter->snapshot) + 2 ||
879
parse_oid_hex(p, &iter->oid, &p) ||
880
!isspace(*p++))
881
die_invalid_line(iter->snapshot->refs->path,
@@ -897,7 +905,7 @@ static int next_record(struct packed_ref_iterator *iter)
905
906
if (iter->pos < iter->eof && *iter->pos == '^') {
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 ||
909
parse_oid_hex(p, &iter->peeled, &p) ||
910
*p++ != '\n')
911
die_invalid_line(iter->snapshot->refs->path,