Skip to content

Commit 34bf44f

Browse files
peffgitster
authored andcommitted
parse-options: mark unused "opt" parameter in callbacks
The previous commit argued that parse-options callbacks should try to use opt->value rather than touching globals directly. In some cases, however, that's awkward to do. Some callbacks touch multiple variables, or may even just call into an abstracted function that does so. In some of these cases we _could_ convert them by stuffing the multiple variables into a single struct and passing the struct pointer through opt->value. But that may make other parts of the code less readable, as the struct relationship has to be mentioned everywhere. Let's just accept that these cases are special and leave them as-is. But we do need to mark their "opt" parameters to satisfy -Wunused-parameter. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 66e3309 commit 34bf44f

File tree

6 files changed

+14
-12
lines changed

6 files changed

+14
-12
lines changed

builtin/gc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,7 @@ static void initialize_task_config(int schedule)
14031403
strbuf_release(&config_name);
14041404
}
14051405

1406-
static int task_option_parse(const struct option *opt,
1406+
static int task_option_parse(const struct option *opt UNUSED,
14071407
const char *arg, int unset)
14081408
{
14091409
int i, num_selected = 0;

builtin/log.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,17 @@ static struct string_list decorate_refs_exclude = STRING_LIST_INIT_NODUP;
118118
static struct string_list decorate_refs_exclude_config = STRING_LIST_INIT_NODUP;
119119
static struct string_list decorate_refs_include = STRING_LIST_INIT_NODUP;
120120

121-
static int clear_decorations_callback(const struct option *opt,
122-
const char *arg, int unset)
121+
static int clear_decorations_callback(const struct option *opt UNUSED,
122+
const char *arg, int unset)
123123
{
124124
string_list_clear(&decorate_refs_include, 0);
125125
string_list_clear(&decorate_refs_exclude, 0);
126126
use_default_decoration_filter = 0;
127127
return 0;
128128
}
129129

130-
static int decorate_callback(const struct option *opt, const char *arg, int unset)
130+
static int decorate_callback(const struct option *opt UNUSED, const char *arg,
131+
int unset)
131132
{
132133
if (unset)
133134
decoration_style = 0;
@@ -1555,7 +1556,8 @@ static int inline_callback(const struct option *opt, const char *arg, int unset)
15551556
return 0;
15561557
}
15571558

1558-
static int header_callback(const struct option *opt, const char *arg, int unset)
1559+
static int header_callback(const struct option *opt UNUSED, const char *arg,
1560+
int unset)
15591561
{
15601562
if (unset) {
15611563
string_list_clear(&extra_hdr, 0);

builtin/merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ static void append_strategy(struct strategy *s)
231231
use_strategies[use_strategies_nr++] = s;
232232
}
233233

234-
static int option_parse_strategy(const struct option *opt,
234+
static int option_parse_strategy(const struct option *opt UNUSED,
235235
const char *name, int unset)
236236
{
237237
if (unset)

builtin/pack-objects.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3739,7 +3739,7 @@ static void show_object__ma_allow_promisor(struct object *obj, const char *name,
37393739
show_object(obj, name, data);
37403740
}
37413741

3742-
static int option_parse_missing_action(const struct option *opt,
3742+
static int option_parse_missing_action(const struct option *opt UNUSED,
37433743
const char *arg, int unset)
37443744
{
37453745
assert(arg);
@@ -4150,7 +4150,7 @@ static int option_parse_index_version(const struct option *opt,
41504150
return 0;
41514151
}
41524152

4153-
static int option_parse_unpack_unreachable(const struct option *opt,
4153+
static int option_parse_unpack_unreachable(const struct option *opt UNUSED,
41544154
const char *arg, int unset)
41554155
{
41564156
if (unset) {
@@ -4165,7 +4165,7 @@ static int option_parse_unpack_unreachable(const struct option *opt,
41654165
return 0;
41664166
}
41674167

4168-
static int option_parse_cruft_expiration(const struct option *opt,
4168+
static int option_parse_cruft_expiration(const struct option *opt UNUSED,
41694169
const char *arg, int unset)
41704170
{
41714171
if (unset) {

builtin/read-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static const char * const read_tree_usage[] = {
4949
NULL
5050
};
5151

52-
static int index_output_cb(const struct option *opt, const char *arg,
52+
static int index_output_cb(const struct option *opt UNUSED, const char *arg,
5353
int unset)
5454
{
5555
BUG_ON_OPT_NEG(unset);

builtin/update-index.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ static int chmod_callback(const struct option *opt,
856856
return 0;
857857
}
858858

859-
static int resolve_undo_clear_callback(const struct option *opt,
859+
static int resolve_undo_clear_callback(const struct option *opt UNUSED,
860860
const char *arg, int unset)
861861
{
862862
BUG_ON_OPT_NEG(unset);
@@ -890,7 +890,7 @@ static int parse_new_style_cacheinfo(const char *arg,
890890
}
891891

892892
static enum parse_opt_result cacheinfo_callback(
893-
struct parse_opt_ctx_t *ctx, const struct option *opt,
893+
struct parse_opt_ctx_t *ctx, const struct option *opt UNUSED,
894894
const char *arg, int unset)
895895
{
896896
struct object_id oid;

0 commit comments

Comments
 (0)