Skip to content

Commit 99d86d6

Browse files
szedergitster
authored andcommitted
parse-options: PARSE_OPT_KEEP_UNKNOWN only applies to --options
The description of 'PARSE_OPT_KEEP_UNKNOWN' starts with "Keep unknown arguments instead of erroring out". This is a bit misleading, as this flag only applies to unknown --options, while non-option arguments are kept even without this flag. Update the description to clarify this, and rename the flag to PARSE_OPTIONS_KEEP_UNKNOWN_OPT to make this obvious just by looking at the flag name. Signed-off-by: SZEDER Gábor <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 80882bc commit 99d86d6

17 files changed

+33
-31
lines changed

Documentation/technical/api-parse-options.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ Flags are the bitwise-or of:
9090
Keep the first argument, which contains the program name. It's
9191
removed from argv[] by default.
9292

93-
`PARSE_OPT_KEEP_UNKNOWN`::
94-
Keep unknown arguments instead of erroring out. This doesn't
93+
`PARSE_OPT_KEEP_UNKNOWN_OPT`::
94+
Keep unknown options instead of erroring out. This doesn't
9595
work for all combinations of arguments as users might expect
9696
it to do. E.g. if the first argument in `--unknown --known`
9797
takes a value (which we can't know), the second one is
@@ -101,6 +101,8 @@ Flags are the bitwise-or of:
101101
non-option, not as a value belonging to the unknown option,
102102
the parser early. That's why parse_options() errors out if
103103
both options are set.
104+
Note that non-option arguments are always kept, even without
105+
this flag.
104106

105107
`PARSE_OPT_NO_INTERNAL_HELP`::
106108
By default, parse_options() handles `-h`, `--help` and

builtin/archive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static int run_remote_archiver(int argc, const char **argv,
7575

7676
#define PARSE_OPT_KEEP_ALL ( PARSE_OPT_KEEP_DASHDASH | \
7777
PARSE_OPT_KEEP_ARGV0 | \
78-
PARSE_OPT_KEEP_UNKNOWN | \
78+
PARSE_OPT_KEEP_UNKNOWN_OPT | \
7979
PARSE_OPT_NO_INTERNAL_HELP )
8080

8181
int cmd_archive(int argc, const char **argv, const char *prefix)

builtin/bisect--helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1324,7 +1324,7 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
13241324

13251325
argc = parse_options(argc, argv, prefix, options,
13261326
git_bisect_helper_usage,
1327-
PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_UNKNOWN);
1327+
PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_UNKNOWN_OPT);
13281328

13291329
if (!cmdmode)
13301330
usage_with_options(git_bisect_helper_usage, options);

builtin/difftool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ int cmd_difftool(int argc, const char **argv, const char *prefix)
716716
symlinks = has_symlinks;
717717

718718
argc = parse_options(argc, argv, prefix, builtin_difftool_options,
719-
builtin_difftool_usage, PARSE_OPT_KEEP_UNKNOWN |
719+
builtin_difftool_usage, PARSE_OPT_KEEP_UNKNOWN_OPT |
720720
PARSE_OPT_KEEP_DASHDASH);
721721

722722
if (tool_help)

builtin/env--helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ int cmd_env__helper(int argc, const char **argv, const char *prefix)
5050
};
5151

5252
argc = parse_options(argc, argv, prefix, opts, env__helper_usage,
53-
PARSE_OPT_KEEP_UNKNOWN);
53+
PARSE_OPT_KEEP_UNKNOWN_OPT);
5454
if (env_default && !*env_default)
5555
usage_with_options(env__helper_usage, opts);
5656
if (!cmdmode)

builtin/fast-export.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1221,7 +1221,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
12211221
revs.sources = &revision_sources;
12221222
revs.rewrite_parents = 1;
12231223
argc = parse_options(argc, argv, prefix, options, fast_export_usage,
1224-
PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN);
1224+
PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT);
12251225
argc = setup_revisions(argc, argv, &revs, NULL);
12261226
if (argc > 1)
12271227
usage_with_options (fast_export_usage, options);

builtin/log.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
199199
mailmap = use_mailmap_config;
200200
argc = parse_options(argc, argv, prefix,
201201
builtin_log_options, builtin_log_usage,
202-
PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN |
202+
PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT |
203203
PARSE_OPT_KEEP_DASHDASH);
204204

205205
if (quiet)
@@ -1926,7 +1926,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
19261926
*/
19271927
argc = parse_options(argc, argv, prefix, builtin_format_patch_options,
19281928
builtin_format_patch_usage,
1929-
PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN |
1929+
PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN_OPT |
19301930
PARSE_OPT_KEEP_DASHDASH);
19311931

19321932
/* Make sure "0000-$sub.patch" gives non-negative length for $sub */

builtin/reflog.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ static int cmd_reflog_show(int argc, const char **argv, const char *prefix)
223223

224224
parse_options(argc, argv, prefix, options, reflog_show_usage,
225225
PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0 |
226-
PARSE_OPT_KEEP_UNKNOWN);
226+
PARSE_OPT_KEEP_UNKNOWN_OPT);
227227

228228
return cmd_log_reflog(argc, argv, prefix);
229229
}
@@ -410,7 +410,7 @@ int cmd_reflog(int argc, const char **argv, const char *prefix)
410410

411411
argc = parse_options(argc, argv, prefix, options, reflog_usage,
412412
PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_ARGV0 |
413-
PARSE_OPT_KEEP_UNKNOWN |
413+
PARSE_OPT_KEEP_UNKNOWN_OPT |
414414
PARSE_OPT_NO_INTERNAL_HELP);
415415

416416
/*

builtin/revert.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ static int run_sequencer(int argc, const char **argv, struct replay_opts *opts)
141141

142142
argc = parse_options(argc, argv, NULL, options, usage_str,
143143
PARSE_OPT_KEEP_ARGV0 |
144-
PARSE_OPT_KEEP_UNKNOWN);
144+
PARSE_OPT_KEEP_UNKNOWN_OPT);
145145

146146
prepare_repo_settings(the_repository);
147147
the_repository->settings.command_requires_full_index = 0;

builtin/sparse-checkout.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ static int sparse_checkout_add(int argc, const char **argv, const char *prefix)
767767
argc = parse_options(argc, argv, prefix,
768768
builtin_sparse_checkout_add_options,
769769
builtin_sparse_checkout_add_usage,
770-
PARSE_OPT_KEEP_UNKNOWN);
770+
PARSE_OPT_KEEP_UNKNOWN_OPT);
771771

772772
sanitize_paths(argc, argv, prefix, add_opts.skip_checks);
773773

@@ -813,7 +813,7 @@ static int sparse_checkout_set(int argc, const char **argv, const char *prefix)
813813
argc = parse_options(argc, argv, prefix,
814814
builtin_sparse_checkout_set_options,
815815
builtin_sparse_checkout_set_usage,
816-
PARSE_OPT_KEEP_UNKNOWN);
816+
PARSE_OPT_KEEP_UNKNOWN_OPT);
817817

818818
if (update_modes(&set_opts.cone_mode, &set_opts.sparse_index))
819819
return 1;

0 commit comments

Comments
 (0)