Skip to content

Commit ab96f28

Browse files
committed
Merge branch 'jk/unused-parameter-fixes'
Various functions have been audited for "-Wunused-parameter" warnings and bugs in them got fixed. * jk/unused-parameter-fixes: midx: double-check large object write loop assert NOARG/NONEG behavior of parse-options callbacks parse-options: drop OPT_DATE() apply: return -1 from option callback instead of calling exit(1) cat-file: report an error on multiple --batch options tag: mark "--message" option with NONEG show-branch: mark --reflog option as NONEG format-patch: mark "--no-numbered" option with NONEG status: mark --find-renames option with NONEG cat-file: mark batch options with NONEG pack-objects: mark index-version option as NONEG ls-files: mark exclude options as NONEG am: handle --no-patch-format option apply: mark include/exclude options as NONEG
2 parents fa2f2f0 + 61b0fcb commit ab96f28

30 files changed

+164
-60
lines changed

Documentation/technical/api-parse-options.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,6 @@ There are some macros to easily define options:
183183
scale the provided value by 1024, 1024^2 or 1024^3 respectively.
184184
The scaled value is put into `unsigned_long_var`.
185185

186-
`OPT_DATE(short, long, &timestamp_t_var, description)`::
187-
Introduce an option with date argument, see `approxidate()`.
188-
The timestamp is put into `timestamp_t_var`.
189-
190186
`OPT_EXPIRY_DATE(short, long, &timestamp_t_var, description)`::
191187
Introduce an option with expiry date argument, see `parse_expiry_date()`.
192188
The timestamp is put into `timestamp_t_var`.

apply.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4772,6 +4772,9 @@ static int apply_option_parse_exclude(const struct option *opt,
47724772
const char *arg, int unset)
47734773
{
47744774
struct apply_state *state = opt->value;
4775+
4776+
BUG_ON_OPT_NEG(unset);
4777+
47754778
add_name_limit(state, arg, 1);
47764779
return 0;
47774780
}
@@ -4780,6 +4783,9 @@ static int apply_option_parse_include(const struct option *opt,
47804783
const char *arg, int unset)
47814784
{
47824785
struct apply_state *state = opt->value;
4786+
4787+
BUG_ON_OPT_NEG(unset);
4788+
47834789
add_name_limit(state, arg, 0);
47844790
state->has_include = 1;
47854791
return 0;
@@ -4790,6 +4796,9 @@ static int apply_option_parse_p(const struct option *opt,
47904796
int unset)
47914797
{
47924798
struct apply_state *state = opt->value;
4799+
4800+
BUG_ON_OPT_NEG(unset);
4801+
47934802
state->p_value = atoi(arg);
47944803
state->p_value_known = 1;
47954804
return 0;
@@ -4799,6 +4808,9 @@ static int apply_option_parse_space_change(const struct option *opt,
47994808
const char *arg, int unset)
48004809
{
48014810
struct apply_state *state = opt->value;
4811+
4812+
BUG_ON_OPT_ARG(arg);
4813+
48024814
if (unset)
48034815
state->ws_ignore_action = ignore_ws_none;
48044816
else
@@ -4810,16 +4822,22 @@ static int apply_option_parse_whitespace(const struct option *opt,
48104822
const char *arg, int unset)
48114823
{
48124824
struct apply_state *state = opt->value;
4825+
4826+
BUG_ON_OPT_NEG(unset);
4827+
48134828
state->whitespace_option = arg;
48144829
if (parse_whitespace_option(state, arg))
4815-
exit(1);
4830+
return -1;
48164831
return 0;
48174832
}
48184833

48194834
static int apply_option_parse_directory(const struct option *opt,
48204835
const char *arg, int unset)
48214836
{
48224837
struct apply_state *state = opt->value;
4838+
4839+
BUG_ON_OPT_NEG(unset);
4840+
48234841
strbuf_reset(&state->root);
48244842
strbuf_addstr(&state->root, arg);
48254843
strbuf_complete(&state->root, '/');
@@ -4939,10 +4957,10 @@ int apply_parse_options(int argc, const char **argv,
49394957
struct option builtin_apply_options[] = {
49404958
{ OPTION_CALLBACK, 0, "exclude", state, N_("path"),
49414959
N_("don't apply changes matching the given path"),
4942-
0, apply_option_parse_exclude },
4960+
PARSE_OPT_NONEG, apply_option_parse_exclude },
49434961
{ OPTION_CALLBACK, 0, "include", state, N_("path"),
49444962
N_("apply changes matching the given path"),
4945-
0, apply_option_parse_include },
4963+
PARSE_OPT_NONEG, apply_option_parse_include },
49464964
{ OPTION_CALLBACK, 'p', NULL, state, N_("num"),
49474965
N_("remove <num> leading slashes from traditional diff paths"),
49484966
0, apply_option_parse_p },

builtin/am.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2113,7 +2113,9 @@ static int parse_opt_patchformat(const struct option *opt, const char *arg, int
21132113
{
21142114
int *opt_value = opt->value;
21152115

2116-
if (!strcmp(arg, "mbox"))
2116+
if (unset)
2117+
*opt_value = PATCH_FORMAT_UNKNOWN;
2118+
else if (!strcmp(arg, "mbox"))
21172119
*opt_value = PATCH_FORMAT_MBOX;
21182120
else if (!strcmp(arg, "stgit"))
21192121
*opt_value = PATCH_FORMAT_STGIT;

builtin/blame.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,8 @@ static int blame_copy_callback(const struct option *option, const char *arg, int
732732
{
733733
int *opt = option->value;
734734

735+
BUG_ON_OPT_NEG(unset);
736+
735737
/*
736738
* -C enables copy from removed files;
737739
* -C -C enables copy from existing files, but only
@@ -754,6 +756,8 @@ static int blame_move_callback(const struct option *option, const char *arg, int
754756
{
755757
int *opt = option->value;
756758

759+
BUG_ON_OPT_NEG(unset);
760+
757761
*opt |= PICKAXE_BLAME_MOVE;
758762

759763
if (arg)

builtin/cat-file.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,8 +603,10 @@ static int batch_option_callback(const struct option *opt,
603603
{
604604
struct batch_options *bo = opt->value;
605605

606+
BUG_ON_OPT_NEG(unset);
607+
606608
if (bo->enabled) {
607-
return 1;
609+
return error(_("only one batch option may be specified"));
608610
}
609611

610612
bo->enabled = 1;
@@ -639,10 +641,12 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
639641
OPT_BOOL(0, "buffer", &batch.buffer_output, N_("buffer --batch output")),
640642
{ OPTION_CALLBACK, 0, "batch", &batch, "format",
641643
N_("show info and content of objects fed from the standard input"),
642-
PARSE_OPT_OPTARG, batch_option_callback },
644+
PARSE_OPT_OPTARG | PARSE_OPT_NONEG,
645+
batch_option_callback },
643646
{ OPTION_CALLBACK, 0, "batch-check", &batch, "format",
644647
N_("show info about objects fed from the standard input"),
645-
PARSE_OPT_OPTARG, batch_option_callback },
648+
PARSE_OPT_OPTARG | PARSE_OPT_NONEG,
649+
batch_option_callback },
646650
OPT_BOOL(0, "follow-symlinks", &batch.follow_symlinks,
647651
N_("follow in-tree symlinks (used with --batch or --batch-check)")),
648652
OPT_BOOL(0, "batch-all-objects", &batch.all_objects,

builtin/checkout-index.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ static const char * const builtin_checkout_index_usage[] = {
132132
static int option_parse_stage(const struct option *opt,
133133
const char *arg, int unset)
134134
{
135+
BUG_ON_OPT_NEG(unset);
136+
135137
if (!strcmp(arg, "all")) {
136138
to_tempfile = 1;
137139
checkout_stage = CHECKOUT_ALL;

builtin/clean.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ static void clean_print_color(enum color_clean ix)
140140
static int exclude_cb(const struct option *opt, const char *arg, int unset)
141141
{
142142
struct string_list *exclude_list = opt->value;
143+
BUG_ON_OPT_NEG(unset);
143144
string_list_append(exclude_list, arg);
144145
return 0;
145146
}

builtin/commit.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ static int opt_parse_m(const struct option *opt, const char *arg, int unset)
161161
static int opt_parse_rename_score(const struct option *opt, const char *arg, int unset)
162162
{
163163
const char **value = opt->value;
164+
165+
BUG_ON_OPT_NEG(unset);
166+
164167
if (arg != NULL && *arg == '=')
165168
arg = arg + 1;
166169

@@ -1335,7 +1338,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
13351338
OPT_BOOL(0, "no-renames", &no_renames, N_("do not detect renames")),
13361339
{ OPTION_CALLBACK, 'M', "find-renames", &rename_score_arg,
13371340
N_("n"), N_("detect renames, optionally set similarity index"),
1338-
PARSE_OPT_OPTARG, opt_parse_rename_score },
1341+
PARSE_OPT_OPTARG | PARSE_OPT_NONEG, opt_parse_rename_score },
13391342
OPT_END(),
13401343
};
13411344

builtin/fetch.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ static int git_fetch_config(const char *k, const char *v, void *cb)
9898

9999
static int parse_refmap_arg(const struct option *opt, const char *arg, int unset)
100100
{
101+
BUG_ON_OPT_NEG(unset);
102+
101103
/*
102104
* "git fetch --refmap='' origin foo"
103105
* can be used to tell the command not to store anywhere

builtin/grep.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,11 +708,14 @@ static int context_callback(const struct option *opt, const char *arg,
708708
static int file_callback(const struct option *opt, const char *arg, int unset)
709709
{
710710
struct grep_opt *grep_opt = opt->value;
711-
int from_stdin = !strcmp(arg, "-");
711+
int from_stdin;
712712
FILE *patterns;
713713
int lno = 0;
714714
struct strbuf sb = STRBUF_INIT;
715715

716+
BUG_ON_OPT_NEG(unset);
717+
718+
from_stdin = !strcmp(arg, "-");
716719
patterns = from_stdin ? stdin : fopen(arg, "r");
717720
if (!patterns)
718721
die_errno(_("cannot open '%s'"), arg);
@@ -733,27 +736,35 @@ static int file_callback(const struct option *opt, const char *arg, int unset)
733736
static int not_callback(const struct option *opt, const char *arg, int unset)
734737
{
735738
struct grep_opt *grep_opt = opt->value;
739+
BUG_ON_OPT_NEG(unset);
740+
BUG_ON_OPT_ARG(arg);
736741
append_grep_pattern(grep_opt, "--not", "command line", 0, GREP_NOT);
737742
return 0;
738743
}
739744

740745
static int and_callback(const struct option *opt, const char *arg, int unset)
741746
{
742747
struct grep_opt *grep_opt = opt->value;
748+
BUG_ON_OPT_NEG(unset);
749+
BUG_ON_OPT_ARG(arg);
743750
append_grep_pattern(grep_opt, "--and", "command line", 0, GREP_AND);
744751
return 0;
745752
}
746753

747754
static int open_callback(const struct option *opt, const char *arg, int unset)
748755
{
749756
struct grep_opt *grep_opt = opt->value;
757+
BUG_ON_OPT_NEG(unset);
758+
BUG_ON_OPT_ARG(arg);
750759
append_grep_pattern(grep_opt, "(", "command line", 0, GREP_OPEN_PAREN);
751760
return 0;
752761
}
753762

754763
static int close_callback(const struct option *opt, const char *arg, int unset)
755764
{
756765
struct grep_opt *grep_opt = opt->value;
766+
BUG_ON_OPT_NEG(unset);
767+
BUG_ON_OPT_ARG(arg);
757768
append_grep_pattern(grep_opt, ")", "command line", 0, GREP_CLOSE_PAREN);
758769
return 0;
759770
}
@@ -762,6 +773,7 @@ static int pattern_callback(const struct option *opt, const char *arg,
762773
int unset)
763774
{
764775
struct grep_opt *grep_opt = opt->value;
776+
BUG_ON_OPT_NEG(unset);
765777
append_grep_pattern(grep_opt, arg, "-e option", 0, GREP_PATTERN);
766778
return 0;
767779
}

0 commit comments

Comments
 (0)