Skip to content

Commit c52a02a

Browse files
committed
Merge branch 'jk/unused-post-2.42-part2'
Unused parameters to functions are marked as such, and/or removed, in order to bring us closer to -Wunused-parameter clean. * jk/unused-post-2.42-part2: parse-options: mark unused parameters in noop callback interpret-trailers: mark unused "unset" parameters in option callbacks parse-options: add more BUG_ON() annotations merge: do not pass unused opt->value parameter parse-options: mark unused "opt" parameter in callbacks parse-options: prefer opt->value to globals in callbacks checkout-index: delay automatic setting of to_tempfile format-patch: use OPT_STRING_LIST for to/cc options merge: simplify parsing of "-n" option merge: make xopts a strvec
2 parents 94e83dc + 0058b3d commit c52a02a

14 files changed

+116
-106
lines changed

builtin/add.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ static char *chmod_arg;
231231

232232
static int ignore_removal_cb(const struct option *opt, const char *arg, int unset)
233233
{
234+
BUG_ON_OPT_ARG(arg);
235+
234236
/* if we are told to ignore, we are not adding removals */
235237
*(int *)opt->value = !unset ? 0 : 1;
236238
return 0;

builtin/checkout-index.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
static int nul_term_line;
2525
static int checkout_stage; /* default to checkout stage0 */
2626
static int ignore_skip_worktree; /* default to 0 */
27-
static int to_tempfile;
27+
static int to_tempfile = -1;
2828
static char topath[4][TEMPORARY_FILENAME_LENGTH + 1];
2929

3030
static struct checkout state = CHECKOUT_INIT;
@@ -193,15 +193,16 @@ static const char * const builtin_checkout_index_usage[] = {
193193
static int option_parse_stage(const struct option *opt,
194194
const char *arg, int unset)
195195
{
196+
int *stage = opt->value;
197+
196198
BUG_ON_OPT_NEG(unset);
197199

198200
if (!strcmp(arg, "all")) {
199-
to_tempfile = 1;
200-
checkout_stage = CHECKOUT_ALL;
201+
*stage = CHECKOUT_ALL;
201202
} else {
202203
int ch = arg[0];
203204
if ('1' <= ch && ch <= '3')
204-
checkout_stage = arg[0] - '0';
205+
*stage = arg[0] - '0';
205206
else
206207
die(_("stage should be between 1 and 3 or all"));
207208
}
@@ -239,7 +240,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
239240
N_("write the content to temporary files")),
240241
OPT_STRING(0, "prefix", &state.base_dir, N_("string"),
241242
N_("when creating files, prepend <string>")),
242-
OPT_CALLBACK_F(0, "stage", NULL, "(1|2|3|all)",
243+
OPT_CALLBACK_F(0, "stage", &checkout_stage, "(1|2|3|all)",
243244
N_("copy out the files from named stage"),
244245
PARSE_OPT_NONEG, option_parse_stage),
245246
OPT_END()
@@ -269,6 +270,12 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
269270
state.base_dir = "";
270271
state.base_dir_len = strlen(state.base_dir);
271272

273+
if (to_tempfile < 0)
274+
to_tempfile = (checkout_stage == CHECKOUT_ALL);
275+
if (!to_tempfile && checkout_stage == CHECKOUT_ALL)
276+
die(_("options '%s' and '%s' cannot be used together"),
277+
"--stage=all", "--no-temp");
278+
272279
/*
273280
* when --prefix is specified we do not want to update cache.
274281
*/

builtin/describe.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,9 +561,11 @@ static void describe(const char *arg, int last_one)
561561
static int option_parse_exact_match(const struct option *opt, const char *arg,
562562
int unset)
563563
{
564+
int *val = opt->value;
565+
564566
BUG_ON_OPT_ARG(arg);
565567

566-
max_candidates = unset ? DEFAULT_CANDIDATES : 0;
568+
*val = unset ? DEFAULT_CANDIDATES : 0;
567569
return 0;
568570
}
569571

@@ -578,7 +580,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
578580
OPT_BOOL(0, "long", &longformat, N_("always use long format")),
579581
OPT_BOOL(0, "first-parent", &first_parent, N_("only follow first parent")),
580582
OPT__ABBREV(&abbrev),
581-
OPT_CALLBACK_F(0, "exact-match", NULL, NULL,
583+
OPT_CALLBACK_F(0, "exact-match", &max_candidates, NULL,
582584
N_("only output exact matches"),
583585
PARSE_OPT_NOARG, option_parse_exact_match),
584586
OPT_INTEGER(0, "candidates", &max_candidates,

builtin/fast-export.c

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ static const char *fast_export_usage[] = {
3333
};
3434

3535
static int progress;
36-
static enum { SIGNED_TAG_ABORT, VERBATIM, WARN, WARN_STRIP, STRIP } signed_tag_mode = SIGNED_TAG_ABORT;
37-
static enum { TAG_FILTERING_ABORT, DROP, REWRITE } tag_of_filtered_mode = TAG_FILTERING_ABORT;
38-
static enum { REENCODE_ABORT, REENCODE_YES, REENCODE_NO } reencode_mode = REENCODE_ABORT;
36+
static enum signed_tag_mode { SIGNED_TAG_ABORT, VERBATIM, WARN, WARN_STRIP, STRIP } signed_tag_mode = SIGNED_TAG_ABORT;
37+
static enum tag_of_filtered_mode { TAG_FILTERING_ABORT, DROP, REWRITE } tag_of_filtered_mode = TAG_FILTERING_ABORT;
38+
static enum reencode_mode { REENCODE_ABORT, REENCODE_YES, REENCODE_NO } reencode_mode = REENCODE_ABORT;
3939
static int fake_missing_tagger;
4040
static int use_done_feature;
4141
static int no_data;
@@ -53,16 +53,18 @@ static struct revision_sources revision_sources;
5353
static int parse_opt_signed_tag_mode(const struct option *opt,
5454
const char *arg, int unset)
5555
{
56+
enum signed_tag_mode *val = opt->value;
57+
5658
if (unset || !strcmp(arg, "abort"))
57-
signed_tag_mode = SIGNED_TAG_ABORT;
59+
*val = SIGNED_TAG_ABORT;
5860
else if (!strcmp(arg, "verbatim") || !strcmp(arg, "ignore"))
59-
signed_tag_mode = VERBATIM;
61+
*val = VERBATIM;
6062
else if (!strcmp(arg, "warn"))
61-
signed_tag_mode = WARN;
63+
*val = WARN;
6264
else if (!strcmp(arg, "warn-strip"))
63-
signed_tag_mode = WARN_STRIP;
65+
*val = WARN_STRIP;
6466
else if (!strcmp(arg, "strip"))
65-
signed_tag_mode = STRIP;
67+
*val = STRIP;
6668
else
6769
return error("Unknown signed-tags mode: %s", arg);
6870
return 0;
@@ -71,12 +73,14 @@ static int parse_opt_signed_tag_mode(const struct option *opt,
7173
static int parse_opt_tag_of_filtered_mode(const struct option *opt,
7274
const char *arg, int unset)
7375
{
76+
enum tag_of_filtered_mode *val = opt->value;
77+
7478
if (unset || !strcmp(arg, "abort"))
75-
tag_of_filtered_mode = TAG_FILTERING_ABORT;
79+
*val = TAG_FILTERING_ABORT;
7680
else if (!strcmp(arg, "drop"))
77-
tag_of_filtered_mode = DROP;
81+
*val = DROP;
7882
else if (!strcmp(arg, "rewrite"))
79-
tag_of_filtered_mode = REWRITE;
83+
*val = REWRITE;
8084
else
8185
return error("Unknown tag-of-filtered mode: %s", arg);
8286
return 0;
@@ -85,21 +89,23 @@ static int parse_opt_tag_of_filtered_mode(const struct option *opt,
8589
static int parse_opt_reencode_mode(const struct option *opt,
8690
const char *arg, int unset)
8791
{
92+
enum reencode_mode *val = opt->value;
93+
8894
if (unset) {
89-
reencode_mode = REENCODE_ABORT;
95+
*val = REENCODE_ABORT;
9096
return 0;
9197
}
9298

9399
switch (git_parse_maybe_bool(arg)) {
94100
case 0:
95-
reencode_mode = REENCODE_NO;
101+
*val = REENCODE_NO;
96102
break;
97103
case 1:
98-
reencode_mode = REENCODE_YES;
104+
*val = REENCODE_YES;
99105
break;
100106
default:
101107
if (!strcasecmp(arg, "abort"))
102-
reencode_mode = REENCODE_ABORT;
108+
*val = REENCODE_ABORT;
103109
else
104110
return error("Unknown reencoding mode: %s", arg);
105111
}

builtin/fetch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ static int parse_refmap_arg(const struct option *opt, const char *arg, int unset
176176
* "git fetch --refmap='' origin foo"
177177
* can be used to tell the command not to store anywhere
178178
*/
179-
refspec_append(&refmap, arg);
179+
refspec_append(opt->value, arg);
180180

181181
return 0;
182182
}
@@ -2204,7 +2204,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
22042204
PARSE_OPT_HIDDEN, option_fetch_parse_recurse_submodules),
22052205
OPT_BOOL(0, "update-shallow", &update_shallow,
22062206
N_("accept refs that update .git/shallow")),
2207-
OPT_CALLBACK_F(0, "refmap", NULL, N_("refmap"),
2207+
OPT_CALLBACK_F(0, "refmap", &refmap, N_("refmap"),
22082208
N_("specify fetch refmap"), PARSE_OPT_NONEG, parse_refmap_arg),
22092209
OPT_STRING_LIST('o', "server-option", &server_options, N_("server-specific"), N_("option to transmit")),
22102210
OPT_IPVERSION(&family),

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/interpret-trailers.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,24 @@ static enum trailer_if_exists if_exists;
2424
static enum trailer_if_missing if_missing;
2525

2626
static int option_parse_where(const struct option *opt,
27-
const char *arg, int unset)
27+
const char *arg, int unset UNUSED)
2828
{
29-
return trailer_set_where(&where, arg);
29+
/* unset implies NULL arg, which is handled in our helper */
30+
return trailer_set_where(opt->value, arg);
3031
}
3132

3233
static int option_parse_if_exists(const struct option *opt,
33-
const char *arg, int unset)
34+
const char *arg, int unset UNUSED)
3435
{
35-
return trailer_set_if_exists(&if_exists, arg);
36+
/* unset implies NULL arg, which is handled in our helper */
37+
return trailer_set_if_exists(opt->value, arg);
3638
}
3739

3840
static int option_parse_if_missing(const struct option *opt,
39-
const char *arg, int unset)
41+
const char *arg, int unset UNUSED)
4042
{
41-
return trailer_set_if_missing(&if_missing, arg);
43+
/* unset implies NULL arg, which is handled in our helper */
44+
return trailer_set_if_missing(opt->value, arg);
4245
}
4346

4447
static void new_trailers_clear(struct list_head *trailers)
@@ -97,11 +100,11 @@ int cmd_interpret_trailers(int argc, const char **argv, const char *prefix)
97100
OPT_BOOL(0, "in-place", &opts.in_place, N_("edit files in place")),
98101
OPT_BOOL(0, "trim-empty", &opts.trim_empty, N_("trim empty trailers")),
99102

100-
OPT_CALLBACK(0, "where", NULL, N_("action"),
103+
OPT_CALLBACK(0, "where", &where, N_("action"),
101104
N_("where to place the new trailer"), option_parse_where),
102-
OPT_CALLBACK(0, "if-exists", NULL, N_("action"),
105+
OPT_CALLBACK(0, "if-exists", &if_exists, N_("action"),
103106
N_("action if trailer already exists"), option_parse_if_exists),
104-
OPT_CALLBACK(0, "if-missing", NULL, N_("action"),
107+
OPT_CALLBACK(0, "if-missing", &if_missing, N_("action"),
105108
N_("action if trailer is missing"), option_parse_if_missing),
106109

107110
OPT_BOOL(0, "only-trailers", &opts.only_trailers, N_("output only the trailers")),

builtin/log.c

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,19 @@ 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
{
124+
BUG_ON_OPT_NEG(unset);
125+
BUG_ON_OPT_ARG(arg);
124126
string_list_clear(&decorate_refs_include, 0);
125127
string_list_clear(&decorate_refs_exclude, 0);
126128
use_default_decoration_filter = 0;
127129
return 0;
128130
}
129131

130-
static int decorate_callback(const struct option *opt, const char *arg, int unset)
132+
static int decorate_callback(const struct option *opt UNUSED, const char *arg,
133+
int unset)
131134
{
132135
if (unset)
133136
decoration_style = 0;
@@ -1564,7 +1567,8 @@ static int inline_callback(const struct option *opt, const char *arg, int unset)
15641567
return 0;
15651568
}
15661569

1567-
static int header_callback(const struct option *opt, const char *arg, int unset)
1570+
static int header_callback(const struct option *opt UNUSED, const char *arg,
1571+
int unset)
15681572
{
15691573
if (unset) {
15701574
string_list_clear(&extra_hdr, 0);
@@ -1576,24 +1580,6 @@ static int header_callback(const struct option *opt, const char *arg, int unset)
15761580
return 0;
15771581
}
15781582

1579-
static int to_callback(const struct option *opt, const char *arg, int unset)
1580-
{
1581-
if (unset)
1582-
string_list_clear(&extra_to, 0);
1583-
else
1584-
string_list_append(&extra_to, arg);
1585-
return 0;
1586-
}
1587-
1588-
static int cc_callback(const struct option *opt, const char *arg, int unset)
1589-
{
1590-
if (unset)
1591-
string_list_clear(&extra_cc, 0);
1592-
else
1593-
string_list_append(&extra_cc, arg);
1594-
return 0;
1595-
}
1596-
15971583
static int from_callback(const struct option *opt, const char *arg, int unset)
15981584
{
15991585
char **from = opt->value;
@@ -1968,8 +1954,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
19681954
OPT_GROUP(N_("Messaging")),
19691955
OPT_CALLBACK(0, "add-header", NULL, N_("header"),
19701956
N_("add email header"), header_callback),
1971-
OPT_CALLBACK(0, "to", NULL, N_("email"), N_("add To: header"), to_callback),
1972-
OPT_CALLBACK(0, "cc", NULL, N_("email"), N_("add Cc: header"), cc_callback),
1957+
OPT_STRING_LIST(0, "to", &extra_to, N_("email"), N_("add To: header")),
1958+
OPT_STRING_LIST(0, "cc", &extra_cc, N_("email"), N_("add Cc: header")),
19731959
OPT_CALLBACK_F(0, "from", &from, N_("ident"),
19741960
N_("set From address to <ident> (or committer ident if absent)"),
19751961
PARSE_OPT_OPTARG, from_callback),

builtin/merge.c

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ static int overwrite_ignore = 1;
7979
static struct strbuf merge_msg = STRBUF_INIT;
8080
static struct strategy **use_strategies;
8181
static size_t use_strategies_nr, use_strategies_alloc;
82-
static const char **xopts;
83-
static size_t xopts_nr, xopts_alloc;
82+
static struct strvec xopts = STRVEC_INIT;
8483
static const char *branch;
8584
static char *branch_mergeoptions;
8685
static int verbosity;
@@ -232,7 +231,7 @@ static void append_strategy(struct strategy *s)
232231
use_strategies[use_strategies_nr++] = s;
233232
}
234233

235-
static int option_parse_strategy(const struct option *opt,
234+
static int option_parse_strategy(const struct option *opt UNUSED,
236235
const char *name, int unset)
237236
{
238237
if (unset)
@@ -242,29 +241,9 @@ static int option_parse_strategy(const struct option *opt,
242241
return 0;
243242
}
244243

245-
static int option_parse_x(const struct option *opt,
246-
const char *arg, int unset)
247-
{
248-
if (unset)
249-
return 0;
250-
251-
ALLOC_GROW(xopts, xopts_nr + 1, xopts_alloc);
252-
xopts[xopts_nr++] = xstrdup(arg);
253-
return 0;
254-
}
255-
256-
static int option_parse_n(const struct option *opt,
257-
const char *arg, int unset)
258-
{
259-
BUG_ON_OPT_ARG(arg);
260-
show_diffstat = unset;
261-
return 0;
262-
}
263-
264244
static struct option builtin_merge_options[] = {
265-
OPT_CALLBACK_F('n', NULL, NULL, NULL,
266-
N_("do not show a diffstat at the end of the merge"),
267-
PARSE_OPT_NOARG, option_parse_n),
245+
OPT_SET_INT('n', NULL, &show_diffstat,
246+
N_("do not show a diffstat at the end of the merge"), 0),
268247
OPT_BOOL(0, "stat", &show_diffstat,
269248
N_("show a diffstat at the end of the merge")),
270249
OPT_BOOL(0, "summary", &show_diffstat, N_("(synonym to --stat)")),
@@ -285,10 +264,10 @@ static struct option builtin_merge_options[] = {
285264
OPT_RERERE_AUTOUPDATE(&allow_rerere_auto),
286265
OPT_BOOL(0, "verify-signatures", &verify_signatures,
287266
N_("verify that the named commit has a valid GPG signature")),
288-
OPT_CALLBACK('s', "strategy", &use_strategies, N_("strategy"),
267+
OPT_CALLBACK('s', "strategy", NULL, N_("strategy"),
289268
N_("merge strategy to use"), option_parse_strategy),
290-
OPT_CALLBACK('X', "strategy-option", &xopts, N_("option=value"),
291-
N_("option for selected merge strategy"), option_parse_x),
269+
OPT_STRVEC('X', "strategy-option", &xopts, N_("option=value"),
270+
N_("option for selected merge strategy")),
292271
OPT_CALLBACK('m', "message", &merge_msg, N_("message"),
293272
N_("merge commit message (for a non-fast-forward merge)"),
294273
option_parse_message),
@@ -749,9 +728,9 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
749728
o.show_rename_progress =
750729
show_progress == -1 ? isatty(2) : show_progress;
751730

752-
for (x = 0; x < xopts_nr; x++)
753-
if (parse_merge_opt(&o, xopts[x]))
754-
die(_("unknown strategy option: -X%s"), xopts[x]);
731+
for (x = 0; x < xopts.nr; x++)
732+
if (parse_merge_opt(&o, xopts.v[x]))
733+
die(_("unknown strategy option: -X%s"), xopts.v[x]);
755734

756735
o.branch1 = head_arg;
757736
o.branch2 = merge_remote_util(remoteheads->item)->name;
@@ -777,7 +756,7 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
777756
return clean ? 0 : 1;
778757
} else {
779758
return try_merge_command(the_repository,
780-
strategy, xopts_nr, xopts,
759+
strategy, xopts.nr, xopts.v,
781760
common, head_arg, remoteheads);
782761
}
783762
}

0 commit comments

Comments
 (0)