Skip to content

Commit

Permalink
Merge branch 'sb/opt-filename'
Browse files Browse the repository at this point in the history
* sb/opt-filename:
  parse-opts: add OPT_FILENAME and transition builtins
  parse-opts: prepare for OPT_FILENAME

Conflicts:
	builtin-log.c
  • Loading branch information
Junio C Hamano committed May 31, 2009
2 parents 714cdcd + df217ed commit f9275c6
Show file tree
Hide file tree
Showing 52 changed files with 144 additions and 96 deletions.
9 changes: 7 additions & 2 deletions Documentation/technical/api-parse-options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ Steps to parse options
. in `cmd_foo(int argc, const char **argv, const char *prefix)`
call

argc = parse_options(argc, argv, builtin_foo_options, builtin_foo_usage, flags);
argc = parse_options(argc, argv, prefix, builtin_foo_options, builtin_foo_usage, flags);
+
`parse_options()` will filter out the processed options of `argv[]` and leave the
non-option arguments in `argv[]`.
`argc` is updated appropriately because of the assignment.
+
You can also pass NULL instead of a usage array as fourth parameter of
You can also pass NULL instead of a usage array as the fifth parameter of
parse_options(), to avoid displaying a help screen with usage info and
option list. This should only be done if necessary, e.g. to implement
a limited parser for only a subset of the options that needs to be run
Expand Down Expand Up @@ -167,6 +167,11 @@ There are some macros to easily define options:
and the result will be put into `var`.
See 'Option Callbacks' below for a more elaborate description.

`OPT_FILENAME(short, long, &var, description)`::
Introduce an option with a filename argument.
The filename will be prefixed by passing the filename along with
the prefix argument of `parse_options()` to `prefix_filename()`.

`OPT_ARGUMENT(long, description)`::
Introduce a long-option argument that will be kept in `argv[]`.

Expand Down
2 changes: 1 addition & 1 deletion archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ static int parse_archive_args(int argc, const char **argv,
OPT_END()
};

argc = parse_options(argc, argv, opts, archive_usage, 0);
argc = parse_options(argc, argv, NULL, opts, archive_usage, 0);

if (remote)
die("Unexpected option --remote");
Expand Down
2 changes: 1 addition & 1 deletion builtin-add.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
int add_new_files;
int require_pathspec;

argc = parse_options(argc, argv, builtin_add_options,
argc = parse_options(argc, argv, prefix, builtin_add_options,
builtin_add_usage, PARSE_OPT_KEEP_ARGV0);
if (patch_interactive)
add_interactive = 1;
Expand Down
7 changes: 2 additions & 5 deletions builtin-apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -3292,7 +3292,7 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
"apply a patch without touching the working tree"),
OPT_BOOLEAN(0, "apply", &force_apply,
"also apply the patch (use with --stat/--summary/--check)"),
OPT_STRING(0, "build-fake-ancestor", &fake_ancestor, "file",
OPT_FILENAME(0, "build-fake-ancestor", &fake_ancestor,
"build a temporary index based on embedded index information"),
{ OPTION_CALLBACK, 'z', NULL, NULL, NULL,
"paths are separated with NUL character",
Expand Down Expand Up @@ -3327,11 +3327,8 @@ int cmd_apply(int argc, const char **argv, const char *unused_prefix)
if (apply_default_whitespace)
parse_whitespace_option(apply_default_whitespace);

argc = parse_options(argc, argv, builtin_apply_options,
argc = parse_options(argc, argv, prefix, builtin_apply_options,
apply_usage, 0);
fake_ancestor = parse_options_fix_filename(prefix, fake_ancestor);
if (fake_ancestor)
fake_ancestor = xstrdup(fake_ancestor);

if (apply_with_reject)
apply = apply_verbosely = 1;
Expand Down
3 changes: 2 additions & 1 deletion builtin-archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ int cmd_archive(int argc, const char **argv, const char *prefix)
OPT_END()
};

argc = parse_options(argc, argv, local_opts, NULL, PARSE_OPT_KEEP_ALL);
argc = parse_options(argc, argv, prefix, local_opts, NULL,
PARSE_OPT_KEEP_ALL);

if (output)
create_output_file(output);
Expand Down
3 changes: 2 additions & 1 deletion builtin-bisect--helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
OPT_END()
};

argc = parse_options(argc, argv, options, git_bisect_helper_usage, 0);
argc = parse_options(argc, argv, prefix, options,
git_bisect_helper_usage, 0);

if (!next_all)
usage_with_options(git_bisect_helper_usage, options);
Expand Down
2 changes: 1 addition & 1 deletion builtin-blame.c
Original file line number Diff line number Diff line change
Expand Up @@ -2229,7 +2229,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
save_commit_buffer = 0;
dashdash_pos = 0;

parse_options_start(&ctx, argc, argv, PARSE_OPT_KEEP_DASHDASH |
parse_options_start(&ctx, argc, argv, prefix, PARSE_OPT_KEEP_DASHDASH |
PARSE_OPT_KEEP_ARGV0);
for (;;) {
switch (parse_options_step(&ctx, options, blame_opt_usage)) {
Expand Down
3 changes: 2 additions & 1 deletion builtin-branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
}
hashcpy(merge_filter_ref, head_sha1);

argc = parse_options(argc, argv, options, builtin_branch_usage, 0);
argc = parse_options(argc, argv, prefix, options, builtin_branch_usage,
0);
if (!!delete + !!rename + !!force_create > 1)
usage_with_options(builtin_branch_usage, options);

Expand Down
2 changes: 1 addition & 1 deletion builtin-cat-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ int cmd_cat_file(int argc, const char **argv, const char *prefix)
if (argc != 3 && argc != 2)
usage_with_options(cat_file_usage, options);

argc = parse_options(argc, argv, options, cat_file_usage, 0);
argc = parse_options(argc, argv, prefix, options, cat_file_usage, 0);

if (opt) {
if (argc == 1)
Expand Down
4 changes: 2 additions & 2 deletions builtin-check-attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
int cnt, i, doubledash;
const char *errstr = NULL;

argc = parse_options(argc, argv, check_attr_options, check_attr_usage,
PARSE_OPT_KEEP_DASHDASH);
argc = parse_options(argc, argv, prefix, check_attr_options,
check_attr_usage, PARSE_OPT_KEEP_DASHDASH);
if (!argc)
usage_with_options(check_attr_usage, check_attr_options);

Expand Down
2 changes: 1 addition & 1 deletion builtin-checkout-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
die("invalid cache");
}

argc = parse_options(argc, argv, builtin_checkout_index_options,
argc = parse_options(argc, argv, prefix, builtin_checkout_index_options,
builtin_checkout_index_usage, 0);
state.force = force;
state.quiet = quiet;
Expand Down
2 changes: 1 addition & 1 deletion builtin-checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)

opts.track = BRANCH_TRACK_UNSPECIFIED;

argc = parse_options(argc, argv, options, checkout_usage,
argc = parse_options(argc, argv, prefix, options, checkout_usage,
PARSE_OPT_KEEP_DASHDASH);

/* --track without -b should DWIM */
Expand Down
3 changes: 2 additions & 1 deletion builtin-clean.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
else
config_set = 1;

argc = parse_options(argc, argv, options, builtin_clean_usage, 0);
argc = parse_options(argc, argv, prefix, options, builtin_clean_usage,
0);

memset(&dir, 0, sizeof(dir));
if (ignored_only)
Expand Down
2 changes: 1 addition & 1 deletion builtin-clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix)

junk_pid = getpid();

argc = parse_options(argc, argv, builtin_clone_options,
argc = parse_options(argc, argv, prefix, builtin_clone_options,
builtin_clone_usage, 0);

if (argc == 0)
Expand Down
13 changes: 4 additions & 9 deletions builtin-commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ static struct option builtin_commit_options[] = {
OPT__VERBOSE(&verbose),
OPT_GROUP("Commit message options"),

OPT_STRING('F', "file", &logfile, "FILE", "read log from file"),
OPT_FILENAME('F', "file", &logfile, "read log from file"),
OPT_STRING(0, "author", &force_author, "AUTHOR", "override author for commit"),
OPT_CALLBACK('m', "message", &message, "MESSAGE", "specify commit message", opt_parse_m),
OPT_STRING('c', "reedit-message", &edit_message, "COMMIT", "reuse and edit message from specified commit "),
OPT_STRING('C', "reuse-message", &use_message, "COMMIT", "reuse message from specified commit"),
OPT_BOOLEAN('s', "signoff", &signoff, "add Signed-off-by:"),
OPT_STRING('t', "template", &template_file, "FILE", "use specified template file"),
OPT_FILENAME('t', "template", &template_file, "use specified template file"),
OPT_BOOLEAN('e', "edit", &edit_flag, "force edit of commit"),

OPT_GROUP("Commit contents options"),
Expand Down Expand Up @@ -697,13 +697,8 @@ static int parse_and_validate_options(int argc, const char *argv[],
{
int f = 0;

argc = parse_options(argc, argv, builtin_commit_options, usage, 0);
logfile = parse_options_fix_filename(prefix, logfile);
if (logfile)
logfile = xstrdup(logfile);
template_file = parse_options_fix_filename(prefix, template_file);
if (template_file)
template_file = xstrdup(template_file);
argc = parse_options(argc, argv, prefix, builtin_commit_options, usage,
0);

if (force_author && !strchr(force_author, '>'))
force_author = find_author_by_nickname(force_author);
Expand Down
3 changes: 2 additions & 1 deletion builtin-config.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ int cmd_config(int argc, const char **argv, const char *unused_prefix)

config_exclusive_filename = getenv(CONFIG_ENVIRONMENT);

argc = parse_options(argc, argv, builtin_config_options, builtin_config_usage,
argc = parse_options(argc, argv, prefix, builtin_config_options,
builtin_config_usage,
PARSE_OPT_STOP_AT_NON_OPTION);

if (use_global_config + use_system_config + !!given_config_file > 1) {
Expand Down
2 changes: 1 addition & 1 deletion builtin-count-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ int cmd_count_objects(int argc, const char **argv, const char *prefix)
OPT_END(),
};

argc = parse_options(argc, argv, opts, count_objects_usage, 0);
argc = parse_options(argc, argv, prefix, opts, count_objects_usage, 0);
/* we do not take arguments other than flags for now */
if (argc)
usage_with_options(count_objects_usage, opts);
Expand Down
2 changes: 1 addition & 1 deletion builtin-describe.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
OPT_END(),
};

argc = parse_options(argc, argv, options, describe_usage, 0);
argc = parse_options(argc, argv, prefix, options, describe_usage, 0);
if (max_candidates < 0)
max_candidates = 0;
else if (max_candidates > MAX_TAGS)
Expand Down
2 changes: 1 addition & 1 deletion builtin-fast-export.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)

init_revisions(&revs, prefix);
argc = setup_revisions(argc, argv, &revs, NULL);
argc = parse_options(argc, argv, options, fast_export_usage, 0);
argc = parse_options(argc, argv, prefix, options, fast_export_usage, 0);
if (argc > 1)
usage_with_options (fast_export_usage, options);

Expand Down
2 changes: 1 addition & 1 deletion builtin-fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
for (i = 1; i < argc; i++)
strbuf_addf(&default_rla, " %s", argv[i]);

argc = parse_options(argc, argv,
argc = parse_options(argc, argv, prefix,
builtin_fetch_options, builtin_fetch_usage, 0);

if (argc == 0)
Expand Down
6 changes: 3 additions & 3 deletions builtin-fmt-merge-msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
struct option options[] = {
OPT_BOOLEAN(0, "log", &merge_summary, "populate log with the shortlog"),
OPT_BOOLEAN(0, "summary", &merge_summary, "alias for --log"),
OPT_STRING('F', "file", &inpath, "file", "file to read from"),
OPT_FILENAME('F', "file", &inpath, "file to read from"),
OPT_END()
};

Expand All @@ -360,10 +360,10 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
int ret;

git_config(fmt_merge_msg_config, NULL);
argc = parse_options(argc, argv, options, fmt_merge_msg_usage, 0);
argc = parse_options(argc, argv, prefix, options, fmt_merge_msg_usage,
0);
if (argc > 0)
usage_with_options(fmt_merge_msg_usage, options);
inpath = parse_options_fix_filename(prefix, inpath);

if (inpath && strcmp(inpath, "-")) {
in = fopen(inpath, "r");
Expand Down
2 changes: 1 addition & 1 deletion builtin-for-each-ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
OPT_END(),
};

parse_options(argc, argv, opts, for_each_ref_usage, 0);
parse_options(argc, argv, prefix, opts, for_each_ref_usage, 0);
if (maxcount < 0) {
error("invalid --count argument: `%d'", maxcount);
usage_with_options(for_each_ref_usage, opts);
Expand Down
2 changes: 1 addition & 1 deletion builtin-fsck.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)

errors_found = 0;

argc = parse_options(argc, argv, fsck_opts, fsck_usage, 0);
argc = parse_options(argc, argv, prefix, fsck_opts, fsck_usage, 0);
if (write_lost_and_found) {
check_full = 1;
include_reflogs = 0;
Expand Down
3 changes: 2 additions & 1 deletion builtin-gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
if (pack_refs < 0)
pack_refs = !is_bare_repository();

argc = parse_options(argc, argv, builtin_gc_options, builtin_gc_usage, 0);
argc = parse_options(argc, argv, prefix, builtin_gc_options,
builtin_gc_usage, 0);
if (argc > 0)
usage_with_options(builtin_gc_usage, builtin_gc_options);

Expand Down
2 changes: 1 addition & 1 deletion builtin-grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
* unrecognized non option is the beginning of the refs list
* that continues up to the -- (if exists), and then paths.
*/
argc = parse_options(argc, argv, options, grep_usage,
argc = parse_options(argc, argv, prefix, options, grep_usage,
PARSE_OPT_KEEP_DASHDASH |
PARSE_OPT_STOP_AT_NON_OPTION |
PARSE_OPT_NO_INTERNAL_HELP);
Expand Down
2 changes: 1 addition & 1 deletion builtin-help.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ int cmd_help(int argc, const char **argv, const char *prefix)
setup_git_directory_gently(&nongit);
git_config(git_help_config, NULL);

argc = parse_options(argc, argv, builtin_help_options,
argc = parse_options(argc, argv, prefix, builtin_help_options,
builtin_help_usage, 0);

if (show_all) {
Expand Down
2 changes: 1 addition & 1 deletion builtin-log.c
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
* like "git format-patch -o a123 HEAD^.." may fail; a123 is
* possibly a valid SHA1.
*/
argc = parse_options(argc, argv, builtin_format_patch_options,
argc = parse_options(argc, argv, prefix, builtin_format_patch_options,
builtin_format_patch_usage,
PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN);

Expand Down
2 changes: 1 addition & 1 deletion builtin-ls-files.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
prefix_offset = strlen(prefix);
git_config(git_default_config, NULL);

argc = parse_options(argc, argv, builtin_ls_files_options,
argc = parse_options(argc, argv, prefix, builtin_ls_files_options,
ls_files_usage, 0);
if (show_tag || show_valid_bit) {
tag_cached = "H ";
Expand Down
2 changes: 1 addition & 1 deletion builtin-merge-base.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int cmd_merge_base(int argc, const char **argv, const char *prefix)
};

git_config(git_default_config, NULL);
argc = parse_options(argc, argv, options, merge_base_usage, 0);
argc = parse_options(argc, argv, prefix, options, merge_base_usage, 0);
if (argc < 2)
usage_with_options(merge_base_usage, options);
rev = xmalloc(argc * sizeof(*rev));
Expand Down
2 changes: 1 addition & 1 deletion builtin-merge-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
merge_style = git_xmerge_style;
}

argc = parse_options(argc, argv, options, merge_file_usage, 0);
argc = parse_options(argc, argv, prefix, options, merge_file_usage, 0);
if (argc != 3)
usage_with_options(merge_file_usage, options);
if (quiet) {
Expand Down
4 changes: 2 additions & 2 deletions builtin-merge.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ static int git_merge_config(const char *k, const char *v, void *cb)
argv = xrealloc(argv, sizeof(*argv) * (argc + 2));
memmove(argv + 1, argv, sizeof(*argv) * (argc + 1));
argc++;
parse_options(argc, argv, builtin_merge_options,
parse_options(argc, argv, NULL, builtin_merge_options,
builtin_merge_usage, 0);
free(buf);
}
Expand Down Expand Up @@ -855,7 +855,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
if (diff_use_color_default == -1)
diff_use_color_default = git_use_color_default;

argc = parse_options(argc, argv, builtin_merge_options,
argc = parse_options(argc, argv, prefix, builtin_merge_options,
builtin_merge_usage, 0);
if (verbosity < 0)
show_diffstat = 0;
Expand Down
2 changes: 1 addition & 1 deletion builtin-mktree.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ int cmd_mktree(int ac, const char **av, const char *prefix)
OPT_END()
};

ac = parse_options(ac, av, option, mktree_usage, 0);
ac = parse_options(ac, av, prefix, option, mktree_usage, 0);

while (!got_eof) {
while (1) {
Expand Down
3 changes: 2 additions & 1 deletion builtin-mv.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
if (read_cache() < 0)
die("index file corrupt");

argc = parse_options(argc, argv, builtin_mv_options, builtin_mv_usage, 0);
argc = parse_options(argc, argv, prefix, builtin_mv_options,
builtin_mv_usage, 0);
if (--argc < 1)
usage_with_options(builtin_mv_usage, builtin_mv_options);

Expand Down
2 changes: 1 addition & 1 deletion builtin-name-rev.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
};

git_config(git_default_config, NULL);
argc = parse_options(argc, argv, opts, name_rev_usage, 0);
argc = parse_options(argc, argv, prefix, opts, name_rev_usage, 0);
if (!!all + !!transform_stdin + !!argc > 1) {
error("Specify either a list, or --all, not both!");
usage_with_options(name_rev_usage, opts);
Expand Down
Loading

0 comments on commit f9275c6

Please sign in to comment.