reftable/writer: fix type used for number of records

Both `reftable_writer_add_refs()` and `reftable_writer_add_logs()` accept an array of records that should be added to the new table. Callers of this function are expected to also pass the number of such records to the function to tell it how many such records it is supposed to write. But while all callers pass in a `size_t`, which is a sensible choice, the function in fact accepts an `int` as argument, which is less so. Fix this. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Aug 12, 2025 at 11:54 UTC 9077923c8ea83f7023c86c517f080396bf96dbb3
2 files changed +11 -10
reftable/reftable-writer.h
+2 -2
@@ -156,7 +156,7 @@ int reftable_writer_add_ref(struct reftable_writer *w,
156 the records before adding them, reordering the records array passed in.
157 */
158 int reftable_writer_add_refs(struct reftable_writer *w,
159 - struct reftable_ref_record *refs, int n);
159 + struct reftable_ref_record *refs, size_t n);
160
161 /*
162 adds reftable_log_records. Log records are keyed by (refname, decreasing
@@ -171,7 +171,7 @@ int reftable_writer_add_log(struct reftable_writer *w,
171 the records before adding them, reordering records array passed in.
172 */
173 int reftable_writer_add_logs(struct reftable_writer *w,
174 - struct reftable_log_record *logs, int n);
174 + struct reftable_log_record *logs, size_t n);
175
176 /* reftable_writer_close finalizes the reftable. The writer is retained so
177 * statistics can be inspected. */
reftable/writer.c
+9 -8
@@ -395,14 +395,15 @@ out:
395 }
396
397 int reftable_writer_add_refs(struct reftable_writer *w,
398 - struct reftable_ref_record *refs, int n)
398 + struct reftable_ref_record *refs, size_t n)
399 {
400 int err = 0;
401 - int i = 0;
401 +
402 QSORT(refs, n, reftable_ref_record_compare_name);
403 - for (i = 0; err == 0 && i < n; i++) {
403 +
404 + for (size_t i = 0; err == 0 && i < n; i++)
405 err = reftable_writer_add_ref(w, &refs[i]);
405 - }
406 +
407 return err;
408 }
409
@@ -486,15 +487,15 @@ done:
487 }
488
489 int reftable_writer_add_logs(struct reftable_writer *w,
489 - struct reftable_log_record *logs, int n)
490 + struct reftable_log_record *logs, size_t n)
491 {
492 int err = 0;
492 - int i = 0;
493 +
494 QSORT(logs, n, reftable_log_record_compare_key);
495
495 - for (i = 0; err == 0 && i < n; i++) {
496 + for (size_t i = 0; err == 0 && i < n; i++)
497 err = reftable_writer_add_log(w, &logs[i]);
497 - }
498 +
499 return err;
500 }
501