reftable: mark unused parameters in virtual functions

The reftable code uses a lot of virtual function pointers, but many of the concrete implementations do not need all of the parameters. For the most part these are obviously fine to just mark as UNUSED (e.g., the empty_iterator functions unsurprisingly do not do anything). Here are a few cases where I dug a little deeper (but still ended up just marking them UNUSED): - the iterator exclude_patterns is best-effort and optional (though it would be nice to support in the long run as an optimization) - ignoring the ref_store in many transaction functions is unexpected, but works because the ref_transaction itself carries enough information to do what we need. - ignoring "err" for in some cases (e.g., transaction abort) is OK because we do not return any errors. It is a little odd for reftable_be_create_reflog(), though, since we do return errors there. We should perhaps be creating string error messages at this layer, but I've punted on that for now. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Aug 17, 2024 at 04:24 UTC 4695c3f3a9a4d6d9785ae9c40ed105302ce08a1e
9 files changed +41 -33
refs/reftable-backend.c
+7 -7
@@ -614,7 +614,7 @@ done:
614
615 static struct ref_iterator *reftable_be_iterator_begin(struct ref_store *ref_store,
616 const char *prefix,
617 - const char **exclude_patterns,
617 + const char **exclude_patterns UNUSED,
618 unsigned int flags)
619 {
620 struct reftable_ref_iterator *main_iter, *worktree_iter;
@@ -1123,9 +1123,9 @@ done:
1123 return ret;
1124 }
1125
1126 -static int reftable_be_transaction_abort(struct ref_store *ref_store,
1126 +static int reftable_be_transaction_abort(struct ref_store *ref_store UNUSED,
1127 struct ref_transaction *transaction,
1128 - struct strbuf *err)
1128 + struct strbuf *err UNUSED)
1129 {
1130 struct reftable_transaction_data *tx_data = transaction->backend_data;
1131 free_transaction_data(tx_data);
@@ -1315,7 +1315,7 @@ done:
1315 return ret;
1316 }
1317
1318 -static int reftable_be_transaction_finish(struct ref_store *ref_store,
1318 +static int reftable_be_transaction_finish(struct ref_store *ref_store UNUSED,
1319 struct ref_transaction *transaction,
1320 struct strbuf *err)
1321 {
@@ -1726,8 +1726,8 @@ static int reftable_reflog_iterator_advance(struct ref_iterator *ref_iterator)
1726 return ITER_OK;
1727 }
1728
1729 -static int reftable_reflog_iterator_peel(struct ref_iterator *ref_iterator,
1730 - struct object_id *peeled)
1729 +static int reftable_reflog_iterator_peel(struct ref_iterator *ref_iterator UNUSED,
1730 + struct object_id *peeled UNUSED)
1731 {
1732 BUG("reftable reflog iterator cannot be peeled");
1733 return -1;
@@ -1988,7 +1988,7 @@ done:
1988
1989 static int reftable_be_create_reflog(struct ref_store *ref_store,
1990 const char *refname,
1991 - struct strbuf *errmsg)
1991 + struct strbuf *errmsg UNUSED)
1992 {
1993 struct reftable_ref_store *refs =
1994 reftable_be_downcast(ref_store, REF_STORE_WRITE, "create_reflog");
reftable/blocksource.c
+4 -4
@@ -13,14 +13,14 @@ https://developers.google.com/open-source/licenses/bsd
13 #include "reftable-blocksource.h"
14 #include "reftable-error.h"
15
16 -static void strbuf_return_block(void *b, struct reftable_block *dest)
16 +static void strbuf_return_block(void *b UNUSED, struct reftable_block *dest)
17 {
18 if (dest->len)
19 memset(dest->data, 0xff, dest->len);
20 reftable_free(dest->data);
21 }
22
23 -static void strbuf_close(void *b)
23 +static void strbuf_close(void *b UNUSED)
24 {
25 }
26
@@ -55,7 +55,7 @@ void block_source_from_strbuf(struct reftable_block_source *bs,
55 bs->arg = buf;
56 }
57
58 -static void malloc_return_block(void *b, struct reftable_block *dest)
58 +static void malloc_return_block(void *b UNUSED, struct reftable_block *dest)
59 {
60 if (dest->len)
61 memset(dest->data, 0xff, dest->len);
@@ -85,7 +85,7 @@ static uint64_t file_size(void *b)
85 return ((struct file_block_source *)b)->size;
86 }
87
88 -static void file_return_block(void *b, struct reftable_block *dest)
88 +static void file_return_block(void *b UNUSED, struct reftable_block *dest UNUSED)
89 {
90 }
91
reftable/generic.c
+5 -3
@@ -201,17 +201,19 @@ int iterator_next(struct reftable_iterator *it, struct reftable_record *rec)
201 return it->ops->next(it->iter_arg, rec);
202 }
203
204 -static int empty_iterator_seek(void *arg, struct reftable_record *want)
204 +static int empty_iterator_seek(void *arg UNUSED,
205 + struct reftable_record *want UNUSED)
206 {
207 return 0;
208 }
209
209 -static int empty_iterator_next(void *arg, struct reftable_record *rec)
210 +static int empty_iterator_next(void *arg UNUSED,
211 + struct reftable_record *rec UNUSED)
212 {
213 return 1;
214 }
215
214 -static void empty_iterator_close(void *arg)
216 +static void empty_iterator_close(void *arg UNUSED)
217 {
218 }
219
reftable/iter.c
+2 -1
@@ -127,7 +127,8 @@ static int indexed_table_ref_iter_next_block(struct indexed_table_ref_iter *it)
127 return 0;
128 }
129
130 -static int indexed_table_ref_iter_seek(void *p, struct reftable_record *want)
130 +static int indexed_table_ref_iter_seek(void *p UNUSED,
131 + struct reftable_record *want UNUSED)
132 {
133 BUG("seeking indexed table is not supported");
134 return -1;
reftable/record.c
+18 -13
@@ -516,7 +516,7 @@ static void reftable_obj_record_release(void *rec)
516 memset(obj, 0, sizeof(struct reftable_obj_record));
517 }
518
519 -static void reftable_obj_record_print(const void *rec, int hash_size)
519 +static void reftable_obj_record_print(const void *rec, int hash_size UNUSED)
520 {
521 const struct reftable_obj_record *obj = rec;
522 char hex[GIT_MAX_HEXSZ + 1] = { 0 };
@@ -532,7 +532,7 @@ static void reftable_obj_record_print(const void *rec, int hash_size)
532 }
533
534 static void reftable_obj_record_copy_from(void *rec, const void *src_rec,
535 - int hash_size)
535 + int hash_size UNUSED)
536 {
537 struct reftable_obj_record *obj = rec;
538 const struct reftable_obj_record *src =
@@ -559,7 +559,7 @@ static uint8_t reftable_obj_record_val_type(const void *rec)
559 }
560
561 static int reftable_obj_record_encode(const void *rec, struct string_view s,
562 - int hash_size)
562 + int hash_size UNUSED)
563 {
564 const struct reftable_obj_record *r = rec;
565 struct string_view start = s;
@@ -594,7 +594,8 @@ static int reftable_obj_record_encode(const void *rec, struct string_view s,
594
595 static int reftable_obj_record_decode(void *rec, struct strbuf key,
596 uint8_t val_type, struct string_view in,
597 - int hash_size, struct strbuf *scratch UNUSED)
597 + int hash_size UNUSED,
598 + struct strbuf *scratch UNUSED)
599 {
600 struct string_view start = in;
601 struct reftable_obj_record *r = rec;
@@ -647,12 +648,13 @@ static int reftable_obj_record_decode(void *rec, struct strbuf key,
648 return start.len - in.len;
649 }
650
650 -static int not_a_deletion(const void *p)
651 +static int not_a_deletion(const void *p UNUSED)
652 {
653 return 0;
654 }
655
655 -static int reftable_obj_record_equal_void(const void *a, const void *b, int hash_size)
656 +static int reftable_obj_record_equal_void(const void *a, const void *b,
657 + int hash_size UNUSED)
658 {
659 struct reftable_obj_record *ra = (struct reftable_obj_record *) a;
660 struct reftable_obj_record *rb = (struct reftable_obj_record *) b;
@@ -1066,7 +1068,7 @@ static void reftable_index_record_key(const void *r, struct strbuf *dest)
1068 }
1069
1070 static void reftable_index_record_copy_from(void *rec, const void *src_rec,
1069 - int hash_size)
1071 + int hash_size UNUSED)
1072 {
1073 struct reftable_index_record *dst = rec;
1074 const struct reftable_index_record *src = src_rec;
@@ -1082,13 +1084,13 @@ static void reftable_index_record_release(void *rec)
1084 strbuf_release(&idx->last_key);
1085 }
1086
1085 -static uint8_t reftable_index_record_val_type(const void *rec)
1087 +static uint8_t reftable_index_record_val_type(const void *rec UNUSED)
1088 {
1089 return 0;
1090 }
1091
1092 static int reftable_index_record_encode(const void *rec, struct string_view out,
1091 - int hash_size)
1093 + int hash_size UNUSED)
1094 {
1095 const struct reftable_index_record *r =
1096 (const struct reftable_index_record *)rec;
@@ -1104,8 +1106,10 @@ static int reftable_index_record_encode(const void *rec, struct string_view out,
1106 }
1107
1108 static int reftable_index_record_decode(void *rec, struct strbuf key,
1107 - uint8_t val_type, struct string_view in,
1108 - int hash_size, struct strbuf *scratch UNUSED)
1109 + uint8_t val_type UNUSED,
1110 + struct string_view in,
1111 + int hash_size UNUSED,
1112 + struct strbuf *scratch UNUSED)
1113 {
1114 struct string_view start = in;
1115 struct reftable_index_record *r = rec;
@@ -1122,7 +1126,8 @@ static int reftable_index_record_decode(void *rec, struct strbuf key,
1126 return start.len - in.len;
1127 }
1128
1125 -static int reftable_index_record_equal(const void *a, const void *b, int hash_size)
1129 +static int reftable_index_record_equal(const void *a, const void *b,
1130 + int hash_size UNUSED)
1131 {
1132 struct reftable_index_record *ia = (struct reftable_index_record *) a;
1133 struct reftable_index_record *ib = (struct reftable_index_record *) b;
@@ -1137,7 +1142,7 @@ static int reftable_index_record_cmp(const void *_a, const void *_b)
1142 return strbuf_cmp(&a->last_key, &b->last_key);
1143 }
1144
1140 -static void reftable_index_record_print(const void *rec, int hash_size)
1145 +static void reftable_index_record_print(const void *rec, int hash_size UNUSED)
1146 {
1147 const struct reftable_index_record *idx = rec;
1148 /* TODO: escape null chars? */
reftable/stack_test.c
+2 -2
@@ -399,7 +399,7 @@ static void test_reftable_stack_auto_compaction_fails_gracefully(void)
399 clear_dir(dir);
400 }
401
402 -static int write_error(struct reftable_writer *wr, void *arg)
402 +static int write_error(struct reftable_writer *wr UNUSED, void *arg)
403 {
404 return *((int *)arg);
405 }
@@ -816,7 +816,7 @@ static void test_reflog_expire(void)
816 reftable_log_record_release(&log);
817 }
818
819 -static int write_nothing(struct reftable_writer *wr, void *arg)
819 +static int write_nothing(struct reftable_writer *wr, void *arg UNUSED)
820 {
821 reftable_writer_set_limits(wr, 1, 1);
822 return 0;
reftable/test_framework.c
+1 -1
@@ -21,7 +21,7 @@ ssize_t strbuf_add_void(void *b, const void *data, size_t sz)
21 return sz;
22 }
23
24 -int noop_flush(void *arg)
24 +int noop_flush(void *arg UNUSED)
25 {
26 return 0;
27 }
reftable/writer.c
+1 -1
@@ -544,7 +544,7 @@ static void write_object_record(void *void_arg, void *key)
544 done:;
545 }
546
547 -static void object_record_free(void *void_arg, void *key)
547 +static void object_record_free(void *void_arg UNUSED, void *key)
548 {
549 struct obj_index_tree_node *entry = key;
550
t/unit-tests/t-reftable-merged.c
+1 -1
@@ -22,7 +22,7 @@ static ssize_t strbuf_add_void(void *b, const void *data, const size_t sz)
22 return sz;
23 }
24
25 -static int noop_flush(void *arg)
25 +static int noop_flush(void *arg UNUSED)
26 {
27 return 0;
28 }