Skip to content

Commit 3778292

Browse files
bebarinogitster
authored andcommitted
parse-opts: prepare for OPT_FILENAME
To give OPT_FILENAME the prefix, we pass the prefix to parse_options() which passes the prefix to parse_options_start() which sets the prefix member of parse_opts_ctx accordingly. If there isn't a prefix in the calling context, passing NULL will suffice. Signed-off-by: Stephen Boyd <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3d09e64 commit 3778292

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+86
-64
lines changed

Documentation/technical/api-parse-options.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ Steps to parse options
6060
. in `cmd_foo(int argc, const char **argv, const char *prefix)`
6161
call
6262

63-
argc = parse_options(argc, argv, builtin_foo_options, builtin_foo_usage, flags);
63+
argc = parse_options(argc, argv, prefix, builtin_foo_options, builtin_foo_usage, flags);
6464
+
6565
`parse_options()` will filter out the processed options of `argv[]` and leave the
6666
non-option arguments in `argv[]`.
6767
`argc` is updated appropriately because of the assignment.
6868
+
69-
You can also pass NULL instead of a usage array as fourth parameter of
69+
You can also pass NULL instead of a usage array as the fifth parameter of
7070
parse_options(), to avoid displaying a help screen with usage info and
7171
option list. This should only be done if necessary, e.g. to implement
7272
a limited parser for only a subset of the options that needs to be run

archive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ static int parse_archive_args(int argc, const char **argv,
309309
OPT_END()
310310
};
311311

312-
argc = parse_options(argc, argv, opts, archive_usage, 0);
312+
argc = parse_options(argc, argv, NULL, opts, archive_usage, 0);
313313

314314
if (remote)
315315
die("Unexpected option --remote");

builtin-add.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
298298
int add_new_files;
299299
int require_pathspec;
300300

301-
argc = parse_options(argc, argv, builtin_add_options,
301+
argc = parse_options(argc, argv, prefix, builtin_add_options,
302302
builtin_add_usage, PARSE_OPT_KEEP_ARGV0);
303303
if (patch_interactive)
304304
add_interactive = 1;

builtin-apply.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3313,7 +3313,7 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
33133313
if (apply_default_whitespace)
33143314
parse_whitespace_option(apply_default_whitespace);
33153315

3316-
argc = parse_options(argc, argv, builtin_apply_options,
3316+
argc = parse_options(argc, argv, prefix, builtin_apply_options,
33173317
apply_usage, 0);
33183318
fake_ancestor = parse_options_fix_filename(prefix, fake_ancestor);
33193319
if (fake_ancestor)

builtin-archive.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ int cmd_archive(int argc, const char **argv, const char *prefix)
8080
OPT_END()
8181
};
8282

83-
argc = parse_options(argc, argv, local_opts, NULL, PARSE_OPT_KEEP_ALL);
83+
argc = parse_options(argc, argv, prefix, local_opts, NULL,
84+
PARSE_OPT_KEEP_ALL);
8485

8586
if (output)
8687
create_output_file(output);

builtin-bisect--helper.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
1717
OPT_END()
1818
};
1919

20-
argc = parse_options(argc, argv, options, git_bisect_helper_usage, 0);
20+
argc = parse_options(argc, argv, prefix, options,
21+
git_bisect_helper_usage, 0);
2122

2223
if (!next_all)
2324
usage_with_options(git_bisect_helper_usage, options);

builtin-blame.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2229,7 +2229,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
22292229
save_commit_buffer = 0;
22302230
dashdash_pos = 0;
22312231

2232-
parse_options_start(&ctx, argc, argv, PARSE_OPT_KEEP_DASHDASH |
2232+
parse_options_start(&ctx, argc, argv, prefix, PARSE_OPT_KEEP_DASHDASH |
22332233
PARSE_OPT_KEEP_ARGV0);
22342234
for (;;) {
22352235
switch (parse_options_step(&ctx, options, blame_opt_usage)) {

builtin-branch.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
610610
}
611611
hashcpy(merge_filter_ref, head_sha1);
612612

613-
argc = parse_options(argc, argv, options, builtin_branch_usage, 0);
613+
argc = parse_options(argc, argv, prefix, options, builtin_branch_usage,
614+
0);
614615
if (!!delete + !!rename + !!force_create > 1)
615616
usage_with_options(builtin_branch_usage, options);
616617

builtin-cat-file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
231231
if (argc != 3 && argc != 2)
232232
usage_with_options(cat_file_usage, options);
233233

234-
argc = parse_options(argc, argv, options, cat_file_usage, 0);
234+
argc = parse_options(argc, argv, prefix, options, cat_file_usage, 0);
235235

236236
if (opt) {
237237
if (argc == 1)

builtin-check-attr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
6969
int cnt, i, doubledash;
7070
const char *errstr = NULL;
7171

72-
argc = parse_options(argc, argv, check_attr_options, check_attr_usage,
73-
PARSE_OPT_KEEP_DASHDASH);
72+
argc = parse_options(argc, argv, prefix, check_attr_options,
73+
check_attr_usage, PARSE_OPT_KEEP_DASHDASH);
7474
if (!argc)
7575
usage_with_options(check_attr_usage, check_attr_options);
7676

0 commit comments

Comments
 (0)