Skip to content

Commit f9275c6

Browse files
committed
Merge branch 'sb/opt-filename'
* sb/opt-filename: parse-opts: add OPT_FILENAME and transition builtins parse-opts: prepare for OPT_FILENAME Conflicts: builtin-log.c
2 parents 714cdcd + df217ed commit f9275c6

Some content is hidden

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

52 files changed

+144
-96
lines changed

Documentation/technical/api-parse-options.txt

Lines changed: 7 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
@@ -167,6 +167,11 @@ There are some macros to easily define options:
167167
and the result will be put into `var`.
168168
See 'Option Callbacks' below for a more elaborate description.
169169

170+
`OPT_FILENAME(short, long, &var, description)`::
171+
Introduce an option with a filename argument.
172+
The filename will be prefixed by passing the filename along with
173+
the prefix argument of `parse_options()` to `prefix_filename()`.
174+
170175
`OPT_ARGUMENT(long, description)`::
171176
Introduce a long-option argument that will be kept in `argv[]`.
172177

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: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3292,7 +3292,7 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
32923292
"apply a patch without touching the working tree"),
32933293
OPT_BOOLEAN(0, "apply", &force_apply,
32943294
"also apply the patch (use with --stat/--summary/--check)"),
3295-
OPT_STRING(0, "build-fake-ancestor", &fake_ancestor, "file",
3295+
OPT_FILENAME(0, "build-fake-ancestor", &fake_ancestor,
32963296
"build a temporary index based on embedded index information"),
32973297
{ OPTION_CALLBACK, 'z', NULL, NULL, NULL,
32983298
"paths are separated with NUL character",
@@ -3327,11 +3327,8 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
33273327
if (apply_default_whitespace)
33283328
parse_whitespace_option(apply_default_whitespace);
33293329

3330-
argc = parse_options(argc, argv, builtin_apply_options,
3330+
argc = parse_options(argc, argv, prefix, builtin_apply_options,
33313331
apply_usage, 0);
3332-
fake_ancestor = parse_options_fix_filename(prefix, fake_ancestor);
3333-
if (fake_ancestor)
3334-
fake_ancestor = xstrdup(fake_ancestor);
33353332

33363333
if (apply_with_reject)
33373334
apply = apply_verbosely = 1;

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)