more -Wunused-parameter annotations
cover more -Wunused-parameter annotations
Here's another set of patches to silence -Wunused-parameter warnings. With the exception of the first patch, these are all just adding annotations (though I tried to document in each one any digging I did on "this isn't a bug that we're not using it, right?").
So I don't think these should be controversial. But I wanted to mention that I'll be offline for a month starting July 5th. So if there is any substantive review after that, I'll be rather slow to respond. :)
[01/14]: test-ref-store: drop unimplemented reflog-expire command [02/14]: do_for_each_ref_helper(): mark unused repository parameter [03/14]: http: mark unused parameters in curl callbacks [04/14]: http-push: mark unused parameter in xml callback [05/14]: am: mark unused keep_cr parameters
[06/14]: count-objects: mark unused parameter in alternates callback [07/14]: revisions: drop unused "opt" parameter in "tweak" callbacks [08/14]: fsck: mark unused parameters in various fsck callbacks [09/14]: merge-tree: mark unused parameter in traverse callback [10/14]: replace: mark unused parameter in ref callback [11/14]: replace: mark unused parameter in each_mergetag_fn callback [12/14]: rev-parse: mark unused parameter in for_each_abbrev callback [13/14]: tag: mark unused parameters in each_tag_name_fn callbacks [14/14]: t/helper: mark unused callback void data parameters
builtin/am.c | 4 ++-- builtin/count-objects.c | 2 +- builtin/diff-tree.c | 2 +- builtin/fsck.c | 10 +++++----- builtin/index-pack.c | 3 ++- builtin/log.c | 6 ++---- builtin/merge-tree.c | 4 +++- builtin/mktag.c | 8 ++++---- builtin/replace.c | 4 ++-- builtin/rev-parse.c | 2 +- builtin/tag.c | 4 ++-- builtin/unpack-objects.c | 3 ++- fsck.c | 4 ++-- http-push.c | 2 +- http.c | 9 ++++++--- object-file.c | 10 +++++----- refs.c | 2 +- revision.c | 2 +- revision.h | 2 +- t/helper/test-dump-split-index.c | 2 +- t/helper/test-oid-array.c | 2 +- t/helper/test-ref-store.c | 6 ------ 22 files changed, 46 insertions(+), 47 deletions(-)
-Peff
PATCH 1/14 test-ref-store: drop unimplemented reflog-expire command
The reflog-expire command has been unimplemented since it was added in 80f2a6097c (t/helper: add test-ref-store to test ref-store functions, 2017-03-26). This causes -Wunused-parameter to complain, since the function just calls die() without looking at its arguments.
We could mark these as UNUSED to silence the warning. But let's just drop the function. It has no callers in the test suite and is not doing anything useful, beyond perhaps reminding us that it's something we _could_ be testing.
But since the bulk of the work in adding such tests would be the shell bits that actually examine the reflog state before and after expiration, this is not even a useful step in that direction. Somebody who wants to do that work later can easily add this function back.
--- t/helper/test-ref-store.c | 6 ------ 1 file changed, 6 deletions(-)
t/helper/test-ref-store.c +0 -6
@@ -268,11 +268,6 @@ static int cmd_delete_reflog(struct ref_store *refs, const char **argv)return refs_delete_reflog (refs, refname); } -static int cmd_reflog_expire (struct ref_store *refs,const char **argv) -{ -die ("not supported yet" ); -} -static int cmd_delete_ref (struct ref_store *refs,const char **argv) {const char *msg =notnull (*argv++,"msg" );
@@ -326,7 +321,6 @@ static struct command commands[] = { { "reflog-exists", cmd_reflog_exists }, { "create-reflog", cmd_create_reflog }, { "delete-reflog", cmd_delete_reflog }, - { "reflog-expire", cmd_reflog_expire },/* * backend transaction functions can't be tested separately */
Signature · 1 line
2.41.0.586.g3c0cc15bc7
PATCH 2/14 do_for_each_ref_helper(): mark unused repository parameter
In reply to Jeff KingThis function gets a repository parameter because it's a callback for do_for_each_repo_ref_iterator(). But it's just a wrapper that passes along each call to a regular each_ref_fn callback, and the latter doesn't accept a repository argument.
Probably in the long run all of the each_ref_fn callbacks should get a repository parameter, too. But changing that now would require updates all over the code base. Until that happens, let's annotate this wrapper callback to quiet the compiler's -Wunused-parameter warning.
--- refs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
refs.c +1 -1
@@ -1588,7 +1588,7 @@ struct do_for_each_ref_help {void *cb_data; }; -static int do_for_each_ref_helper(struct repository *r, +static int do_for_each_ref_helper(struct repository *r UNUSED, const char *refname, const struct object_id *oid, int flags,
Signature · 1 line
2.41.0.586.g3c0cc15bc7
PATCH 3/14 http: mark unused parameters in curl callbacks
In reply to Jeff KingThese functions are all used as callbacks for curl, so they have to conform to a particular interface. But they don't need all of their parameters:
- fwrite_null() throws away the input, so it doesn't look at most parameters
- fwrite_wwwauth() in theory could take the auth struct in its void pointer, but instead we just access it as the global http_auth (matching the rest of the code in this file)
- curl_trace() always writes via the trace mechanism, so it doesn't need its void pointer to know where to send things. Likewise, it ignores the CURL parameter, since nothing we trace requires querying the handle.
--- http.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
http.c +6 -3
@@ -196,7 +196,7 @@ static inline int is_hdr_continuation(const char *ptr, const size_t size)return size && (*ptr ==' ' || *ptr =='\t' ); } -static size_t fwrite_wwwauth (char *ptr,size_t eltsize,size_t nmemb,void *p) +static size_t fwrite_wwwauth(char *ptr, size_t eltsize, size_t nmemb, void *p UNUSED) {size_t size = eltsize * nmemb;struct strvec *values = &http_auth.wwwauth_headers;
@@ -295,7 +295,8 @@ static size_t fwrite_wwwauth(char *ptr, size_t eltsize, size_t nmemb, void *p)return size; } -size_t fwrite_null (char *ptr,size_t eltsize,size_t nmemb,void *strbuf) +size_t fwrite_null(char *ptr UNUSED, size_t eltsize UNUSED, size_t nmemb, + void *data UNUSED) {return nmemb; }
@@ -820,7 +821,9 @@ static void curl_dump_info(char *data, size_t size)strbuf_release (&buf); } -static int curl_trace (CURL *handle,curl_infotype type,char *data,size_t size,void *userp) +static int curl_trace(CURL *handle UNUSED, curl_infotype type, +char *data,size_t size, + void *userp UNUSED) {const char *text;enum {NO_FILTER =0 ,DO_FILTER =1 };
Signature · 1 line
2.41.0.586.g3c0cc15bc7
PATCH 4/14 http-push: mark unused parameter in xml callback
In reply to Jeff KingThe xml_start_tag() function is passed the expat library's XML_SetElementHandler() function, so it has to conform to the expected interface. But we don't actually care about the attributes list. Mark it so that -Wunused-parameter does not complain.
--- http-push.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
http-push.c +1 -1
@@ -783,7 +783,7 @@ static void handle_new_lock_ctx(struct xml_ctx *ctx, int tag_closed)static void one_remote_ref (const char *refname);static void -xml_start_tag (void *userData,const char *name,const char **atts) +xml_start_tag(void *userData, const char *name, const char **atts UNUSED) {struct xml_ctx *ctx = (struct xml_ctx *)userData;const char *c =strchr (name,':' );
Signature · 1 line
2.41.0.586.g3c0cc15bc7
PATCH 5/14 am: mark unused keep_cr parameters
In reply to Jeff KingWhen parsing the input, we have a "keep_cr" parameter to tell us how to handle line endings. But this doesn't apply to stgit or hg patches (which are not mailbox formats where we have to worry about that), so we ignore the parameter entirely in those functions.
Let's mark these as unused so that -Wunused-parameter does not complain about them.
Note that we could just drop these parameters entirely. They are necessary to conform to the mail_conv_fn interface used by split_mail_conv(), but these two callbacks are the only ones used with that function. The other formats (which _do_ care about keep_cr) use split_mail_mbox(). But it's conceivable that we'd eventually add another format that does care about this option, so let's leave it as part of the generic interface.
--- builtin/am.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
builtin/am.c +2 -2
@@ -787,7 +787,7 @@ static int split_mail_conv(mail_conv_fn fn, struct am_state *state,* A split_mail_conv() callback that converts an StGit patch to an RFC2822 * message suitable for parsing with git-mailinfo. */ -static int stgit_patch_to_mail (FILE *out,FILE *in,int keep_cr) +static int stgit_patch_to_mail(FILE *out, FILE *in, int keep_cr UNUSED) {struct strbuf sb =STRBUF_INIT ;int subject_printed =0 ;
@@ -870,7 +870,7 @@ static int split_mail_stgit_series(struct am_state *state, const char **paths,* A split_patches_conv() callback that converts a mercurial patch to a RFC2822 * message suitable for parsing with git-mailinfo. */ -static int hg_patch_to_mail (FILE *out,FILE *in,int keep_cr) +static int hg_patch_to_mail(FILE *out, FILE *in, int keep_cr UNUSED) {struct strbuf sb =STRBUF_INIT ;int rc =0 ;
Signature · 1 line
2.41.0.586.g3c0cc15bc7
PATCH 6/14 count-objects: mark unused parameter in alternates callback
In reply to Jeff KingCallbacks to for_each_altodb() get a void data pointer, but we don't need it here. Mark it as unused to silence -Wunused-parameter.
--- builtin/count-objects.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/count-objects.c +1 -1
@@ -82,7 +82,7 @@ static int count_cruft(const char *basename UNUSED, const char *path,return 0 ; } -static int print_alternate (struct object_directory *odb,void *data) +static int print_alternate(struct object_directory *odb, void *data UNUSED) {printf ("alternate: " );quote_c_style (odb->path,NULL , stdout,0 );
Signature · 1 line
2.41.0.586.g3c0cc15bc7
PATCH 7/14 revisions: drop unused "opt" parameter in "tweak" callbacks
In reply to Jeff KingThe setup_revision_opt struct has a "tweak" function pointer, which can be used to adjust parameters after setup_revisions() parses arguments, but before it finalizes setup. In addition to the rev_info struct, the callback receives a pointer to the setup_revision_opt, as well.
But none of the existing callbacks looks at the extra "opt" parameter, leading to -Wunused-parameter warnings.
We could mark it as UNUSED, but instead let's remove it entirely. It's conceivable that it could be useful for a callback to have access to the "opt" struct. But in the 13 years that this mechanism has existed, nobody has used it. So let's just drop it in the name of simplifying.
--- builtin/diff-tree.c | 2 +- builtin/log.c | 6 ++---- revision.c | 2 +- revision.h | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-)
builtin/diff-tree.c +1 -1
@@ -99,7 +99,7 @@ static const char diff_tree_usage[] =" --root include the initial commit as diff against /dev/null\n" COMMON_DIFF_OPTIONS_HELP ; -static void diff_tree_tweak_rev (struct rev_info *rev,struct setup_revision_opt *opt) +static void diff_tree_tweak_rev (struct rev_info *rev) {if (!rev->diffopt.output_format) {if (rev->dense_combined_merges)
builtin/log.c +2 -4
@@ -718,8 +718,7 @@ static int show_tree_object(const struct object_id *oid UNUSED,return 0 ; } -static void show_setup_revisions_tweak (struct rev_info *rev, -struct setup_revision_opt *opt) +static void show_setup_revisions_tweak (struct rev_info *rev) {if (rev->first_parent_only)diff_merges_default_to_first_parent (rev);
@@ -862,8 +861,7 @@ int cmd_log_reflog(int argc, const char **argv, const char *prefix)return cmd_log_deinit (cmd_log_walk (&rev), &rev); } -static void log_setup_revisions_tweak (struct rev_info *rev, -struct setup_revision_opt *opt) +static void log_setup_revisions_tweak (struct rev_info *rev) {if (rev->diffopt.flags.default_follow_renames &&diff_check_follow_pathspec (&rev->prune_data,0 ))
revision.c +1 -1
@@ -2955,7 +2955,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct sif (!revs->def) revs->def = opt ? opt->def :NULL ;if (opt && opt->tweak) - opt->tweak (revs, opt); + opt->tweak (revs);if (revs->show_merge)prepare_show_merge (revs);if (revs->def && !revs->pending.nr && !revs->rev_input_given) {
revision.h +1 -1
@@ -428,7 +428,7 @@ void repo_init_revisions(struct repository *r,*/ struct setup_revision_opt {const char *def; -void (*tweak)(struct rev_info *,struct setup_revision_opt *); +void (*tweak)(struct rev_info *);unsigned int assume_dashdash:1 , allow_exclude_promisor_objects:1 , free_removed_argv_elements:1 ;
Signature · 1 line
2.41.0.586.g3c0cc15bc7
PATCH 8/14 fsck: mark unused parameters in various fsck callbacks
In reply to Jeff KingThere are a few callback functions which are used with the fsck code, but it's natural that not all callbacks need all parameters. For reporting, even something as obvious as "the oid of the object which had a problem" is not always used, as some callers are only checking a single object in the first place. And for both reporting and walking, things like void data pointers and the fsck_options aren't always necessary.
But since each such parameter is used by _some_ callback, we have to keep them in the interface. Mark the unused ones in specific callbacks to avoid triggering -Wunused-parameter.
--- builtin/fsck.c | 10 +++++----- builtin/index-pack.c | 3 ++- builtin/mktag.c | 8 ++++---- builtin/unpack-objects.c | 3 ++- fsck.c | 4 ++-- object-file.c | 10 +++++----- 6 files changed, 20 insertions(+), 18 deletions(-)
builtin/fsck.c +5 -5
@@ -92,11 +92,11 @@ static int objerror(struct object *obj, const char *err)return -1 ; } -static int fsck_error_func (struct fsck_options *o, +static int fsck_error_func(struct fsck_options *o UNUSED,const struct object_id *oid,enum object_type object_type,enum fsck_msg_type msg_type, -enum fsck_msg_id msg_id, + enum fsck_msg_id msg_id UNUSED,const char *message) {switch (msg_type) {
@@ -121,7 +121,7 @@ static int fsck_error_func(struct fsck_options *o,static struct object_array pending;static int mark_object (struct object *obj,enum object_type type, -void *data,struct fsck_options *options) + void *data, struct fsck_options *options UNUSED) {struct object *parent = data;
@@ -206,8 +206,8 @@ static int traverse_reachable(void)return !!result; } -static int mark_used (struct object *obj,enum object_type object_type, -void *data,struct fsck_options *options) +static int mark_used(struct object *obj, int type UNUSED, + void *data UNUSED, struct fsck_options *options UNUSED) {if (!obj)return 1 ;
builtin/index-pack.c +2 -1
@@ -223,7 +223,8 @@ static void cleanup_thread(void) }static int mark_link (struct object *obj,enum object_type type, -void *data,struct fsck_options *options) + void *data UNUSED, + struct fsck_options *options UNUSED) {if (!obj)return -1 ;
builtin/mktag.c +4 -4
@@ -18,11 +18,11 @@ static int option_strict = 1;static struct fsck_options fsck_options =FSCK_OPTIONS_STRICT ; -static int mktag_fsck_error_func (struct fsck_options *o, -const struct object_id *oid, -enum object_type object_type, +static int mktag_fsck_error_func(struct fsck_options *o UNUSED, + const struct object_id *oid UNUSED, + enum object_type object_type UNUSED,enum fsck_msg_type msg_type, -enum fsck_msg_id msg_id, + enum fsck_msg_id msg_id UNUSED,const char *message) {switch (msg_type) {
builtin/unpack-objects.c +2 -1
@@ -214,7 +214,8 @@ static void write_cached_object(struct object *obj, struct obj_buffer *obj_buf)* Verify its reachability and validity recursively and write it out. */ static int check_object (struct object *obj,enum object_type type, -void *data,struct fsck_options *options) + void *data UNUSED, + struct fsck_options *options UNUSED) {struct obj_buffer *obj_buf;
fsck.c +2 -2
@@ -1307,9 +1307,9 @@ int fsck_buffer(const struct object_id *oid, enum object_type type,int fsck_error_function (struct fsck_options *o,const struct object_id *oid, -enum object_type object_type, + enum object_type object_type UNUSED,enum fsck_msg_type msg_type, -enum fsck_msg_id msg_id, + enum fsck_msg_id msg_id UNUSED,const char *message) {if (msg_type ==FSCK_WARN ) {
object-file.c +5 -5
@@ -2308,11 +2308,11 @@ int repo_has_object_file(struct repository *r,* report the minimal fsck error here, and rely on the caller to * give more context. */ -static int hash_format_check_report (struct fsck_options *opts, -const struct object_id *oid, -enum object_type object_type, -enum fsck_msg_type msg_type, -enum fsck_msg_id msg_id, +static int hash_format_check_report(struct fsck_options *opts UNUSED, + const struct object_id *oid UNUSED, + enum object_type object_type UNUSED, + enum fsck_msg_type msg_type UNUSED, + enum fsck_msg_id msg_id UNUSED,const char *message) {error (_ ("object fails fsck: %s" ), message);
Signature · 1 line
2.41.0.586.g3c0cc15bc7
PATCH 9/14 merge-tree: mark unused parameter in traverse callback
In reply to Jeff KingOur threeway_callback() does not bother to look at its "n" parameter. It is static in this file and used only by trivial_merge_trees(), which always passes 3 trees (hence the name "threeway"). It also does not look at "dirmask". This is OK, as it handles directories specifically by looking at the mode bits.
Other traverse_info callbacks need these, so we can't get drop them from the interface. But let's annotate these ones to avoid complaints from -Wunused-parameter.
--- builtin/merge-tree.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
builtin/merge-tree.c +3 -1
@@ -324,7 +324,9 @@ static void unresolved(const struct traverse_info *info, struct name_entry n[3])* The successful merge rules are the same as for the three-way merge * in git-read-tree. */ -static int threeway_callback (int n,unsigned long mask,unsigned long dirmask,struct name_entry *entry,struct traverse_info *info) +static int threeway_callback(int n UNUSED, unsigned long mask, +unsigned long dirmask UNUSED , +struct name_entry *entry,struct traverse_info *info) {/* Same in both? */ if (same_entry (entry+1 , entry+2 ) ||both_empty (entry+1 , entry+2 )) {
Signature · 1 line
2.41.0.586.g3c0cc15bc7
PATCH 10/14 replace: mark unused parameter in ref callback
In reply to Jeff KingWe don't look at the "flags" parameter, which is natural for something that is just printing the contents of the replace refs. But let's mark it to appease -Wunused-parameter.
This probably should have been part of 63e14ee2d6 (refs: mark unused each_ref_fn parameters, 2022-08-19), but I missed it as this one is a repo_each_ref_fn, which takes an extra repository argument.
--- builtin/replace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/replace.c +1 -1
@@ -49,7 +49,7 @@ struct show_data {static int show_reference (struct repository *r,const char *refname,const struct object_id *oid, -int flag,void *cb_data) + int flag UNUSED, void *cb_data) {struct show_data *data = cb_data;
Signature · 1 line
2.41.0.586.g3c0cc15bc7
PATCH 11/14 replace: mark unused parameter in each_mergetag_fn callback
In reply to Jeff KingWe don't look at the "commit" parameter to our callback, as our "mergetag_data" pointer contains the original name "ref", which we use instead. But we can't get rid of it, since other for_each_mergetag callbacks do use it. Let's mark the parameter to avoid -Wunused-parameter warnings.
--- builtin/replace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/replace.c +1 -1
@@ -409,7 +409,7 @@ struct check_mergetag_data {const char **argv; }; -static int check_one_mergetag (struct commit *commit, +static int check_one_mergetag(struct commit *commit UNUSED,struct commit_extra_header *extra,void *data) {
Signature · 1 line
2.41.0.586.g3c0cc15bc7
PATCH 12/14 rev-parse: mark unused parameter in for_each_abbrev callback
In reply to Jeff KingWe don't need to use the "data" parameter in this instance. Let's mark it to avoid -Wunused-parameter warnings.
--- builtin/rev-parse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/rev-parse.c +1 -1
@@ -226,7 +226,7 @@ static int anti_reference(const char *refname, const struct object_id *oid,return 0 ; } -static int show_abbrev (const struct object_id *oid,void *cb_data) +static int show_abbrev(const struct object_id *oid, void *cb_data UNUSED) {show_rev (NORMAL , oid,NULL );return 0 ;
Signature · 1 line
2.41.0.586.g3c0cc15bc7
PATCH 13/14 tag: mark unused parameters in each_tag_name_fn callbacks
In reply to Jeff KingWe iterate over the set of input tag names using callbacks. But not all operations need the same inputs, so some parameters go unused (but of course not the same ones for each operation). Mark the unused ones to avoid -Wunused-parameter warnings.
--- builtin/tag.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
builtin/tag.c +2 -2
@@ -121,7 +121,7 @@ static int for_each_tag_name(const char **argv, each_tag_name_fn fn,return had_error; } -static int collect_tags (const char *name,const char *ref, +static int collect_tags(const char *name UNUSED, const char *ref,const struct object_id *oid,void *cb_data) {struct string_list *ref_list = cb_data;
@@ -155,7 +155,7 @@ static int delete_tags(const char **argv)return result; } -static int verify_tag (const char *name,const char *ref, +static int verify_tag(const char *name, const char *ref UNUSED,const struct object_id *oid,void *cb_data) {int flags;
Signature · 1 line
2.41.0.586.g3c0cc15bc7
PATCH 14/14 t/helper: mark unused callback void data parameters
In reply to Jeff KingMany callback interfaces have an extra void data parameter, but we don't always need it (especially for dumping functions like the ones in test helpers). Mark them as unused to avoid -Wunused-parameter warnings.
--- t/helper/test-dump-split-index.c | 2 +- t/helper/test-oid-array.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
t/helper/test-dump-split-index.c +1 -1
@@ -7,7 +7,7 @@#include "split-index.h" #include "ewah/ewok.h" -static void show_bit (size_t pos,void *data) +static void show_bit(size_t pos, void *data UNUSED) {printf (" %d" , (int )pos); }
t/helper/test-oid-array.c +1 -1
@@ -4,7 +4,7 @@#include "setup.h" #include "strbuf.h" -static int print_oid (const struct object_id *oid,void *data) +static int print_oid(const struct object_id *oid, void *data UNUSED) {puts (oid_to_hex (oid));return 0 ;
Signature · 1 line
2.41.0.586.g3c0cc15bc7