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
This commit is contained in:
Junio C Hamano 2023-09-13 10:07:56 -07:00
commit c52a02a0f0
14 changed files with 116 additions and 106 deletions

View file

@ -231,6 +231,8 @@ static char *chmod_arg;
static int ignore_removal_cb(const struct option *opt, const char *arg, int unset)
{
BUG_ON_OPT_ARG(arg);
/* if we are told to ignore, we are not adding removals */
*(int *)opt->value = !unset ? 0 : 1;
return 0;

View file

@ -24,7 +24,7 @@
static int nul_term_line;
static int checkout_stage; /* default to checkout stage0 */
static int ignore_skip_worktree; /* default to 0 */
static int to_tempfile;
static int to_tempfile = -1;
static char topath[4][TEMPORARY_FILENAME_LENGTH + 1];
static struct checkout state = CHECKOUT_INIT;
@ -193,15 +193,16 @@ static const char * const builtin_checkout_index_usage[] = {
static int option_parse_stage(const struct option *opt,
const char *arg, int unset)
{
int *stage = opt->value;
BUG_ON_OPT_NEG(unset);
if (!strcmp(arg, "all")) {
to_tempfile = 1;
checkout_stage = CHECKOUT_ALL;
*stage = CHECKOUT_ALL;
} else {
int ch = arg[0];
if ('1' <= ch && ch <= '3')
checkout_stage = arg[0] - '0';
*stage = arg[0] - '0';
else
die(_("stage should be between 1 and 3 or all"));
}
@ -239,7 +240,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
N_("write the content to temporary files")),
OPT_STRING(0, "prefix", &state.base_dir, N_("string"),
N_("when creating files, prepend <string>")),
OPT_CALLBACK_F(0, "stage", NULL, "(1|2|3|all)",
OPT_CALLBACK_F(0, "stage", &checkout_stage, "(1|2|3|all)",
N_("copy out the files from named stage"),
PARSE_OPT_NONEG, option_parse_stage),
OPT_END()
@ -269,6 +270,12 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
state.base_dir = "";
state.base_dir_len = strlen(state.base_dir);
if (to_tempfile < 0)
to_tempfile = (checkout_stage == CHECKOUT_ALL);
if (!to_tempfile && checkout_stage == CHECKOUT_ALL)
die(_("options '%s' and '%s' cannot be used together"),
"--stage=all", "--no-temp");
/*
* when --prefix is specified we do not want to update cache.
*/

View file

@ -561,9 +561,11 @@ static void describe(const char *arg, int last_one)
static int option_parse_exact_match(const struct option *opt, const char *arg,
int unset)
{
int *val = opt->value;
BUG_ON_OPT_ARG(arg);
max_candidates = unset ? DEFAULT_CANDIDATES : 0;
*val = unset ? DEFAULT_CANDIDATES : 0;
return 0;
}
@ -578,7 +580,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
OPT_BOOL(0, "long", &longformat, N_("always use long format")),
OPT_BOOL(0, "first-parent", &first_parent, N_("only follow first parent")),
OPT__ABBREV(&abbrev),
OPT_CALLBACK_F(0, "exact-match", NULL, NULL,
OPT_CALLBACK_F(0, "exact-match", &max_candidates, NULL,
N_("only output exact matches"),
PARSE_OPT_NOARG, option_parse_exact_match),
OPT_INTEGER(0, "candidates", &max_candidates,

View file

@ -33,9 +33,9 @@ static const char *fast_export_usage[] = {
};
static int progress;
static enum { SIGNED_TAG_ABORT, VERBATIM, WARN, WARN_STRIP, STRIP } signed_tag_mode = SIGNED_TAG_ABORT;
static enum { TAG_FILTERING_ABORT, DROP, REWRITE } tag_of_filtered_mode = TAG_FILTERING_ABORT;
static enum { REENCODE_ABORT, REENCODE_YES, REENCODE_NO } reencode_mode = REENCODE_ABORT;
static enum signed_tag_mode { SIGNED_TAG_ABORT, VERBATIM, WARN, WARN_STRIP, STRIP } signed_tag_mode = SIGNED_TAG_ABORT;
static enum tag_of_filtered_mode { TAG_FILTERING_ABORT, DROP, REWRITE } tag_of_filtered_mode = TAG_FILTERING_ABORT;
static enum reencode_mode { REENCODE_ABORT, REENCODE_YES, REENCODE_NO } reencode_mode = REENCODE_ABORT;
static int fake_missing_tagger;
static int use_done_feature;
static int no_data;
@ -53,16 +53,18 @@ static struct revision_sources revision_sources;
static int parse_opt_signed_tag_mode(const struct option *opt,
const char *arg, int unset)
{
enum signed_tag_mode *val = opt->value;
if (unset || !strcmp(arg, "abort"))
signed_tag_mode = SIGNED_TAG_ABORT;
*val = SIGNED_TAG_ABORT;
else if (!strcmp(arg, "verbatim") || !strcmp(arg, "ignore"))
signed_tag_mode = VERBATIM;
*val = VERBATIM;
else if (!strcmp(arg, "warn"))
signed_tag_mode = WARN;
*val = WARN;
else if (!strcmp(arg, "warn-strip"))
signed_tag_mode = WARN_STRIP;
*val = WARN_STRIP;
else if (!strcmp(arg, "strip"))
signed_tag_mode = STRIP;
*val = STRIP;
else
return error("Unknown signed-tags mode: %s", arg);
return 0;
@ -71,12 +73,14 @@ static int parse_opt_signed_tag_mode(const struct option *opt,
static int parse_opt_tag_of_filtered_mode(const struct option *opt,
const char *arg, int unset)
{
enum tag_of_filtered_mode *val = opt->value;
if (unset || !strcmp(arg, "abort"))
tag_of_filtered_mode = TAG_FILTERING_ABORT;
*val = TAG_FILTERING_ABORT;
else if (!strcmp(arg, "drop"))
tag_of_filtered_mode = DROP;
*val = DROP;
else if (!strcmp(arg, "rewrite"))
tag_of_filtered_mode = REWRITE;
*val = REWRITE;
else
return error("Unknown tag-of-filtered mode: %s", arg);
return 0;
@ -85,21 +89,23 @@ static int parse_opt_tag_of_filtered_mode(const struct option *opt,
static int parse_opt_reencode_mode(const struct option *opt,
const char *arg, int unset)
{
enum reencode_mode *val = opt->value;
if (unset) {
reencode_mode = REENCODE_ABORT;
*val = REENCODE_ABORT;
return 0;
}
switch (git_parse_maybe_bool(arg)) {
case 0:
reencode_mode = REENCODE_NO;
*val = REENCODE_NO;
break;
case 1:
reencode_mode = REENCODE_YES;
*val = REENCODE_YES;
break;
default:
if (!strcasecmp(arg, "abort"))
reencode_mode = REENCODE_ABORT;
*val = REENCODE_ABORT;
else
return error("Unknown reencoding mode: %s", arg);
}

View file

@ -176,7 +176,7 @@ static int parse_refmap_arg(const struct option *opt, const char *arg, int unset
* "git fetch --refmap='' origin foo"
* can be used to tell the command not to store anywhere
*/
refspec_append(&refmap, arg);
refspec_append(opt->value, arg);
return 0;
}
@ -2204,7 +2204,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
PARSE_OPT_HIDDEN, option_fetch_parse_recurse_submodules),
OPT_BOOL(0, "update-shallow", &update_shallow,
N_("accept refs that update .git/shallow")),
OPT_CALLBACK_F(0, "refmap", NULL, N_("refmap"),
OPT_CALLBACK_F(0, "refmap", &refmap, N_("refmap"),
N_("specify fetch refmap"), PARSE_OPT_NONEG, parse_refmap_arg),
OPT_STRING_LIST('o', "server-option", &server_options, N_("server-specific"), N_("option to transmit")),
OPT_IPVERSION(&family),

View file

@ -1403,7 +1403,7 @@ static void initialize_task_config(int schedule)
strbuf_release(&config_name);
}
static int task_option_parse(const struct option *opt,
static int task_option_parse(const struct option *opt UNUSED,
const char *arg, int unset)
{
int i, num_selected = 0;

View file

@ -24,21 +24,24 @@ static enum trailer_if_exists if_exists;
static enum trailer_if_missing if_missing;
static int option_parse_where(const struct option *opt,
const char *arg, int unset)
const char *arg, int unset UNUSED)
{
return trailer_set_where(&where, arg);
/* unset implies NULL arg, which is handled in our helper */
return trailer_set_where(opt->value, arg);
}
static int option_parse_if_exists(const struct option *opt,
const char *arg, int unset)
const char *arg, int unset UNUSED)
{
return trailer_set_if_exists(&if_exists, arg);
/* unset implies NULL arg, which is handled in our helper */
return trailer_set_if_exists(opt->value, arg);
}
static int option_parse_if_missing(const struct option *opt,
const char *arg, int unset)
const char *arg, int unset UNUSED)
{
return trailer_set_if_missing(&if_missing, arg);
/* unset implies NULL arg, which is handled in our helper */
return trailer_set_if_missing(opt->value, arg);
}
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)
OPT_BOOL(0, "in-place", &opts.in_place, N_("edit files in place")),
OPT_BOOL(0, "trim-empty", &opts.trim_empty, N_("trim empty trailers")),
OPT_CALLBACK(0, "where", NULL, N_("action"),
OPT_CALLBACK(0, "where", &where, N_("action"),
N_("where to place the new trailer"), option_parse_where),
OPT_CALLBACK(0, "if-exists", NULL, N_("action"),
OPT_CALLBACK(0, "if-exists", &if_exists, N_("action"),
N_("action if trailer already exists"), option_parse_if_exists),
OPT_CALLBACK(0, "if-missing", NULL, N_("action"),
OPT_CALLBACK(0, "if-missing", &if_missing, N_("action"),
N_("action if trailer is missing"), option_parse_if_missing),
OPT_BOOL(0, "only-trailers", &opts.only_trailers, N_("output only the trailers")),

View file

@ -118,16 +118,19 @@ static struct string_list decorate_refs_exclude = STRING_LIST_INIT_NODUP;
static struct string_list decorate_refs_exclude_config = STRING_LIST_INIT_NODUP;
static struct string_list decorate_refs_include = STRING_LIST_INIT_NODUP;
static int clear_decorations_callback(const struct option *opt,
const char *arg, int unset)
static int clear_decorations_callback(const struct option *opt UNUSED,
const char *arg, int unset)
{
BUG_ON_OPT_NEG(unset);
BUG_ON_OPT_ARG(arg);
string_list_clear(&decorate_refs_include, 0);
string_list_clear(&decorate_refs_exclude, 0);
use_default_decoration_filter = 0;
return 0;
}
static int decorate_callback(const struct option *opt, const char *arg, int unset)
static int decorate_callback(const struct option *opt UNUSED, const char *arg,
int unset)
{
if (unset)
decoration_style = 0;
@ -1564,7 +1567,8 @@ static int inline_callback(const struct option *opt, const char *arg, int unset)
return 0;
}
static int header_callback(const struct option *opt, const char *arg, int unset)
static int header_callback(const struct option *opt UNUSED, const char *arg,
int unset)
{
if (unset) {
string_list_clear(&extra_hdr, 0);
@ -1576,24 +1580,6 @@ static int header_callback(const struct option *opt, const char *arg, int unset)
return 0;
}
static int to_callback(const struct option *opt, const char *arg, int unset)
{
if (unset)
string_list_clear(&extra_to, 0);
else
string_list_append(&extra_to, arg);
return 0;
}
static int cc_callback(const struct option *opt, const char *arg, int unset)
{
if (unset)
string_list_clear(&extra_cc, 0);
else
string_list_append(&extra_cc, arg);
return 0;
}
static int from_callback(const struct option *opt, const char *arg, int unset)
{
char **from = opt->value;
@ -1968,8 +1954,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
OPT_GROUP(N_("Messaging")),
OPT_CALLBACK(0, "add-header", NULL, N_("header"),
N_("add email header"), header_callback),
OPT_CALLBACK(0, "to", NULL, N_("email"), N_("add To: header"), to_callback),
OPT_CALLBACK(0, "cc", NULL, N_("email"), N_("add Cc: header"), cc_callback),
OPT_STRING_LIST(0, "to", &extra_to, N_("email"), N_("add To: header")),
OPT_STRING_LIST(0, "cc", &extra_cc, N_("email"), N_("add Cc: header")),
OPT_CALLBACK_F(0, "from", &from, N_("ident"),
N_("set From address to <ident> (or committer ident if absent)"),
PARSE_OPT_OPTARG, from_callback),

View file

@ -79,8 +79,7 @@ static int overwrite_ignore = 1;
static struct strbuf merge_msg = STRBUF_INIT;
static struct strategy **use_strategies;
static size_t use_strategies_nr, use_strategies_alloc;
static const char **xopts;
static size_t xopts_nr, xopts_alloc;
static struct strvec xopts = STRVEC_INIT;
static const char *branch;
static char *branch_mergeoptions;
static int verbosity;
@ -232,7 +231,7 @@ static void append_strategy(struct strategy *s)
use_strategies[use_strategies_nr++] = s;
}
static int option_parse_strategy(const struct option *opt,
static int option_parse_strategy(const struct option *opt UNUSED,
const char *name, int unset)
{
if (unset)
@ -242,29 +241,9 @@ static int option_parse_strategy(const struct option *opt,
return 0;
}
static int option_parse_x(const struct option *opt,
const char *arg, int unset)
{
if (unset)
return 0;
ALLOC_GROW(xopts, xopts_nr + 1, xopts_alloc);
xopts[xopts_nr++] = xstrdup(arg);
return 0;
}
static int option_parse_n(const struct option *opt,
const char *arg, int unset)
{
BUG_ON_OPT_ARG(arg);
show_diffstat = unset;
return 0;
}
static struct option builtin_merge_options[] = {
OPT_CALLBACK_F('n', NULL, NULL, NULL,
N_("do not show a diffstat at the end of the merge"),
PARSE_OPT_NOARG, option_parse_n),
OPT_SET_INT('n', NULL, &show_diffstat,
N_("do not show a diffstat at the end of the merge"), 0),
OPT_BOOL(0, "stat", &show_diffstat,
N_("show a diffstat at the end of the merge")),
OPT_BOOL(0, "summary", &show_diffstat, N_("(synonym to --stat)")),
@ -285,10 +264,10 @@ static struct option builtin_merge_options[] = {
OPT_RERERE_AUTOUPDATE(&allow_rerere_auto),
OPT_BOOL(0, "verify-signatures", &verify_signatures,
N_("verify that the named commit has a valid GPG signature")),
OPT_CALLBACK('s', "strategy", &use_strategies, N_("strategy"),
OPT_CALLBACK('s', "strategy", NULL, N_("strategy"),
N_("merge strategy to use"), option_parse_strategy),
OPT_CALLBACK('X', "strategy-option", &xopts, N_("option=value"),
N_("option for selected merge strategy"), option_parse_x),
OPT_STRVEC('X', "strategy-option", &xopts, N_("option=value"),
N_("option for selected merge strategy")),
OPT_CALLBACK('m', "message", &merge_msg, N_("message"),
N_("merge commit message (for a non-fast-forward merge)"),
option_parse_message),
@ -749,9 +728,9 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
o.show_rename_progress =
show_progress == -1 ? isatty(2) : show_progress;
for (x = 0; x < xopts_nr; x++)
if (parse_merge_opt(&o, xopts[x]))
die(_("unknown strategy option: -X%s"), xopts[x]);
for (x = 0; x < xopts.nr; x++)
if (parse_merge_opt(&o, xopts.v[x]))
die(_("unknown strategy option: -X%s"), xopts.v[x]);
o.branch1 = head_arg;
o.branch2 = merge_remote_util(remoteheads->item)->name;
@ -777,7 +756,7 @@ static int try_merge_strategy(const char *strategy, struct commit_list *common,
return clean ? 0 : 1;
} else {
return try_merge_command(the_repository,
strategy, xopts_nr, xopts,
strategy, xopts.nr, xopts.v,
common, head_arg, remoteheads);
}
}

View file

@ -3738,7 +3738,7 @@ static void show_object__ma_allow_promisor(struct object *obj, const char *name,
show_object(obj, name, data);
}
static int option_parse_missing_action(const struct option *opt,
static int option_parse_missing_action(const struct option *opt UNUSED,
const char *arg, int unset)
{
assert(arg);
@ -4119,34 +4119,37 @@ static void add_extra_kept_packs(const struct string_list *names)
static int option_parse_quiet(const struct option *opt, const char *arg,
int unset)
{
int *val = opt->value;
BUG_ON_OPT_ARG(arg);
if (!unset)
progress = 0;
else if (!progress)
progress = 1;
*val = 0;
else if (!*val)
*val = 1;
return 0;
}
static int option_parse_index_version(const struct option *opt,
const char *arg, int unset)
{
struct pack_idx_option *popts = opt->value;
char *c;
const char *val = arg;
BUG_ON_OPT_NEG(unset);
pack_idx_opts.version = strtoul(val, &c, 10);
if (pack_idx_opts.version > 2)
popts->version = strtoul(val, &c, 10);
if (popts->version > 2)
die(_("unsupported index version %s"), val);
if (*c == ',' && c[1])
pack_idx_opts.off32_limit = strtoul(c+1, &c, 0);
if (*c || pack_idx_opts.off32_limit & 0x80000000)
popts->off32_limit = strtoul(c+1, &c, 0);
if (*c || popts->off32_limit & 0x80000000)
die(_("bad index version '%s'"), val);
return 0;
}
static int option_parse_unpack_unreachable(const struct option *opt,
static int option_parse_unpack_unreachable(const struct option *opt UNUSED,
const char *arg, int unset)
{
if (unset) {
@ -4161,7 +4164,7 @@ static int option_parse_unpack_unreachable(const struct option *opt,
return 0;
}
static int option_parse_cruft_expiration(const struct option *opt,
static int option_parse_cruft_expiration(const struct option *opt UNUSED,
const char *arg, int unset)
{
if (unset) {
@ -4189,7 +4192,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
LIST_OBJECTS_FILTER_INIT;
struct option pack_objects_options[] = {
OPT_CALLBACK_F('q', "quiet", NULL, NULL,
OPT_CALLBACK_F('q', "quiet", &progress, NULL,
N_("do not show progress meter"),
PARSE_OPT_NOARG, option_parse_quiet),
OPT_SET_INT(0, "progress", &progress,
@ -4199,7 +4202,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix)
OPT_BOOL(0, "all-progress-implied",
&all_progress_implied,
N_("similar to --all-progress when progress meter is shown")),
OPT_CALLBACK_F(0, "index-version", NULL, N_("<version>[,<offset>]"),
OPT_CALLBACK_F(0, "index-version", &pack_idx_opts, N_("<version>[,<offset>]"),
N_("write the pack index file in the specified idx format version"),
PARSE_OPT_NONEG, option_parse_index_version),
OPT_MAGNITUDE(0, "max-pack-size", &pack_size_limit,

View file

@ -49,7 +49,7 @@ static const char * const read_tree_usage[] = {
NULL
};
static int index_output_cb(const struct option *opt, const char *arg,
static int index_output_cb(const struct option *opt UNUSED, const char *arg,
int unset)
{
BUG_ON_OPT_NEG(unset);

View file

@ -856,7 +856,7 @@ static int chmod_callback(const struct option *opt,
return 0;
}
static int resolve_undo_clear_callback(const struct option *opt,
static int resolve_undo_clear_callback(const struct option *opt UNUSED,
const char *arg, int unset)
{
BUG_ON_OPT_NEG(unset);
@ -890,7 +890,7 @@ static int parse_new_style_cacheinfo(const char *arg,
}
static enum parse_opt_result cacheinfo_callback(
struct parse_opt_ctx_t *ctx, const struct option *opt,
struct parse_opt_ctx_t *ctx, const struct option *opt UNUSED,
const char *arg, int unset)
{
struct object_id oid;

View file

@ -227,7 +227,9 @@ int parse_opt_strvec(const struct option *opt, const char *arg, int unset)
return 0;
}
int parse_opt_noop_cb(const struct option *opt, const char *arg, int unset)
int parse_opt_noop_cb(const struct option *opt UNUSED,
const char *arg UNUSED,
int unset UNUSED)
{
return 0;
}

View file

@ -117,6 +117,26 @@ test_expect_success 'checkout all stages/one file to temporary files' '
test $(cat $s3) = tree3path1)
'
test_expect_success '--stage=all implies --temp' '
rm -f path* .merge_* actual &&
git checkout-index --stage=all -- path1 &&
test_path_is_missing path1
'
test_expect_success 'overriding --stage=all resets implied --temp' '
rm -f path* .merge_* actual &&
git checkout-index --stage=all --stage=2 -- path1 &&
echo tree2path1 >expect &&
test_cmp expect path1
'
test_expect_success '--stage=all --no-temp is rejected' '
rm -f path* .merge_* actual &&
test_must_fail git checkout-index --stage=all --no-temp -- path1 2>err &&
grep -v "already exists" err &&
grep "options .--stage=all. and .--no-temp. cannot be used together" err
'
test_expect_success 'checkout some stages/one file to temporary files' '
rm -f path* .merge_* actual &&
git checkout-index --stage=all --temp -- path2 >actual &&