summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 3d09e64)
raw | patch | inline | side by side (parent: 3d09e64)
author | Stephen Boyd <bebarino@gmail.com> | |
Sat, 23 May 2009 18:53:12 +0000 (11:53 -0700) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 25 May 2009 08:07:25 +0000 (01:07 -0700) |
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 <bebarino@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
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 <bebarino@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
51 files changed:
diff --git a/Documentation/technical/api-parse-options.txt b/Documentation/technical/api-parse-options.txt
index b43458eae6787caab163fadab113dff61e577498..aace5801ca8bf7334b73917e88f6e42ec978727e 100644 (file)
. 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
diff --git a/archive.c b/archive.c
index b2b90d31700d3aa50a3ac0626c1a8561c37c49b7..0bca9ca4038ace99c32eff2e042290b03b2324b7 100644 (file)
--- a/archive.c
+++ b/archive.c
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");
diff --git a/builtin-add.c b/builtin-add.c
index bee45f00de7d82e07b617716033f0d5605b2a368..c1b229a9d8a026ec88cdbf0492856021cacc8097 100644 (file)
--- a/builtin-add.c
+++ b/builtin-add.c
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;
diff --git a/builtin-apply.c b/builtin-apply.c
index a40b9822425e25272cadf6f4170ba967eacf11bf..bac03d7902cb836f2ceb449b8f49e7b4005c0970 100644 (file)
--- a/builtin-apply.c
+++ b/builtin-apply.c
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)
diff --git a/builtin-archive.c b/builtin-archive.c
index ab50cebba0e6798996cc007ced9079c3f0b94a29..3c5a5a7822afebf87ef6eb1f89c7c54d76844161 100644 (file)
--- a/builtin-archive.c
+++ b/builtin-archive.c
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);
index cb3e15511611240cbc3ea53a1a591fdee19ba0b9..5b226399e1c30b23a7b5d226a3f45efe9dbedf45 100644 (file)
--- a/builtin-bisect--helper.c
+++ b/builtin-bisect--helper.c
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);
diff --git a/builtin-blame.c b/builtin-blame.c
index cf74a926149668b7e67544aecd46a0e05d4f59d9..9dc333591045b4232e47eec32488e5a2104540c7 100644 (file)
--- a/builtin-blame.c
+++ b/builtin-blame.c
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)) {
diff --git a/builtin-branch.c b/builtin-branch.c
index 6aaa708473231848db8cba061f6048d41a6782af..5687d6042ced29e60aa1999dc9d73eb6c38b8e77 100644 (file)
--- a/builtin-branch.c
+++ b/builtin-branch.c
}
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);
diff --git a/builtin-cat-file.c b/builtin-cat-file.c
index 8fad19daedef8a38674ee35cd543983bad610857..991e40fb2e01155c2fb9bf875781a8222ddfc715 100644 (file)
--- a/builtin-cat-file.c
+++ b/builtin-cat-file.c
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)
diff --git a/builtin-check-attr.c b/builtin-check-attr.c
index 15a04b7179a09492764d43c16a3ec5ff7cdd1b61..8bd043009829fb4bb40cd2f730cbffa27c3791cf 100644 (file)
--- a/builtin-check-attr.c
+++ b/builtin-check-attr.c
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);
index afe35e246c5ab2b262683308def787c6abce2a83..a7a5ee10f32d52c7555f85f2dcf6c567425488dd 100644 (file)
--- a/builtin-checkout-index.c
+++ b/builtin-checkout-index.c
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;
diff --git a/builtin-checkout.c b/builtin-checkout.c
index b8a4b0139b3b9c2f731315413a73db30edaf9231..8a9a474218c128b7878647045ba471df9902636a 100644 (file)
--- a/builtin-checkout.c
+++ b/builtin-checkout.c
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 */
diff --git a/builtin-clean.c b/builtin-clean.c
index c5ad33d3e665f6d1613df2dfba235b03765565ac..1c1b6d26e9987800d2a414e49e4f371a4277b96e 100644 (file)
--- a/builtin-clean.c
+++ b/builtin-clean.c
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)
diff --git a/builtin-clone.c b/builtin-clone.c
index c935833c6ce176caf47a14b5ad1f2848f0d1ab22..5c46496a43a8fe2f91b395563b266e79a8b94429 100644 (file)
--- a/builtin-clone.c
+++ b/builtin-clone.c
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)
diff --git a/builtin-commit.c b/builtin-commit.c
index baaa75cf908d57e6d8540b6483684400c0b2494b..b9a1528c9d4aa91a18e4f3b645592551f5ea2157 100644 (file)
--- a/builtin-commit.c
+++ b/builtin-commit.c
{
int f = 0;
- argc = parse_options(argc, argv, builtin_commit_options, usage, 0);
+ argc = parse_options(argc, argv, prefix, builtin_commit_options, usage,
+ 0);
logfile = parse_options_fix_filename(prefix, logfile);
if (logfile)
logfile = xstrdup(logfile);
diff --git a/builtin-config.c b/builtin-config.c
index a81bc8bbf033fac83ad6deecbf4a67ba44e06a0b..60915f91caff02997222d18bc625d242d95c6bb1 100644 (file)
--- a/builtin-config.c
+++ b/builtin-config.c
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) {
index b814fe5070873f5c87fc6bbfde480e3b0a83e397..1b0b6c84ea4279df56b82c5a406adbea59e58513 100644 (file)
--- a/builtin-count-objects.c
+++ b/builtin-count-objects.c
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);
diff --git a/builtin-describe.c b/builtin-describe.c
index 63c6a19da5b38bc7c00c624c080ba0afbb10ff8a..7a662980d102a275fceb8299bba0b84b41a8f9cb 100644 (file)
--- a/builtin-describe.c
+++ b/builtin-describe.c
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)
diff --git a/builtin-fast-export.c b/builtin-fast-export.c
index 6731713223d4df24614417cc4285cbee793151d3..6cef8103127a8748acb64ca7ec7a7a95fb639cd3 100644 (file)
--- a/builtin-fast-export.c
+++ b/builtin-fast-export.c
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);
diff --git a/builtin-fetch.c b/builtin-fetch.c
index 77acabfcc71aaee02ea99d2cd10e51dd0feaea6e..0ed6016da190f421b79819d9d1545e061dbffbdf 100644 (file)
--- a/builtin-fetch.c
+++ b/builtin-fetch.c
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)
index fae1482ba91937232f427a3f5dd03c587c3fba57..d4c72061429329473266abaa7128f810b19f5084 100644 (file)
--- a/builtin-fmt-merge-msg.c
+++ b/builtin-fmt-merge-msg.c
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);
diff --git a/builtin-for-each-ref.c b/builtin-for-each-ref.c
index d091e04af9549b70a1e15a4b845383056e71932e..784733b25d21f292c6ac895ba34d0a7b88b3073f 100644 (file)
--- a/builtin-for-each-ref.c
+++ b/builtin-for-each-ref.c
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);
diff --git a/builtin-fsck.c b/builtin-fsck.c
index 6436bc224840f11af2f7fa26c61b62c25d78d865..7da706cac3bef05f03c09955d41b4e5077558d4f 100644 (file)
--- a/builtin-fsck.c
+++ b/builtin-fsck.c
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;
diff --git a/builtin-gc.c b/builtin-gc.c
index fc556ed7f3fb68734fd783e5b38e6b050bed9c5b..7d3e9cc7a04e0aa3eb378cb54b7b71fe17981c95 100644 (file)
--- a/builtin-gc.c
+++ b/builtin-gc.c
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);
diff --git a/builtin-grep.c b/builtin-grep.c
index 5308b346e69a50d7695b26f3b8e00bfdf71e1dd2..73fc922c4995369c0ca86c01200e2a0ea39161ab 100644 (file)
--- a/builtin-grep.c
+++ b/builtin-grep.c
* 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);
diff --git a/builtin-help.c b/builtin-help.c
index 67dda3e6e63c9130a6f1e1c94cb35e519d765a95..af565fb6588a900bca322381af6cbd93ca35d09e 100644 (file)
--- a/builtin-help.c
+++ b/builtin-help.c
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) {
diff --git a/builtin-log.c b/builtin-log.c
index 5d39565e940e5218d697ccf671574e8d6188cd5a..ea8dbc869808d8fa80bcf5c46236273ff0a0ca8c 100644 (file)
--- a/builtin-log.c
+++ b/builtin-log.c
* 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);
diff --git a/builtin-ls-files.c b/builtin-ls-files.c
index 3d59b0e140ca199997704ffcf59fbc2138345168..2312866605c4140ac4e5a9f5bb963ca5ab5c6da3 100644 (file)
--- a/builtin-ls-files.c
+++ b/builtin-ls-files.c
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 ";
diff --git a/builtin-merge-base.c b/builtin-merge-base.c
index 03fc1c211453f1ed09ee2c6b71d438b0bfbf474f..a6ec2f7ab76db27afbb63aacf3bba60b4e73b3f6 100644 (file)
--- a/builtin-merge-base.c
+++ b/builtin-merge-base.c
};
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));
diff --git a/builtin-merge-file.c b/builtin-merge-file.c
index 96edb97a8327ba64cccf64bfa341e94d9f903e94..afd2ea7a732460c431328dbd4c0141a49d638244 100644 (file)
--- a/builtin-merge-file.c
+++ b/builtin-merge-file.c
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) {
diff --git a/builtin-merge.c b/builtin-merge.c
index 0b58e5eda1f38c1560cc9dcf69be37fa5fc9886f..8d101eff0b433bd5afa6cf1e027e50447fdf5370 100644 (file)
--- a/builtin-merge.c
+++ b/builtin-merge.c
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);
}
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;
diff --git a/builtin-mktree.c b/builtin-mktree.c
index dc4f1a711df0e84657c9f1ea3edcba20c9764e75..098395fda1932674e29f8d2cb332c722a6cb275f 100644 (file)
--- a/builtin-mktree.c
+++ b/builtin-mktree.c
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) {
diff --git a/builtin-mv.c b/builtin-mv.c
index 01270fefdfb04ed27379b1ca761a811b929ce887..8b81d4b51d78bb2aa49430102ab585afce9cccdf 100644 (file)
--- a/builtin-mv.c
+++ b/builtin-mv.c
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);
diff --git a/builtin-name-rev.c b/builtin-name-rev.c
index 08c8aabf9428447abad7def693d7b22c5330e180..06a38ac8c10126085e6477c205d450da089faae2 100644 (file)
--- a/builtin-name-rev.c
+++ b/builtin-name-rev.c
};
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);
diff --git a/builtin-pack-refs.c b/builtin-pack-refs.c
index 34246df4ec946273d9f42e6f0848b02d8510beea..091860b2e370561f0811399b0d307e732e9eaac3 100644 (file)
--- a/builtin-pack-refs.c
+++ b/builtin-pack-refs.c
OPT_BIT(0, "prune", &flags, "prune loose refs (default)", PACK_REFS_PRUNE),
OPT_END(),
};
- if (parse_options(argc, argv, opts, pack_refs_usage, 0))
+ if (parse_options(argc, argv, prefix, opts, pack_refs_usage, 0))
usage_with_options(pack_refs_usage, opts);
return pack_refs(flags);
}
diff --git a/builtin-prune.c b/builtin-prune.c
index 145ba83651e9c8560e20d6ab449ce64783bc65f5..0ed9cce4a23aa575c1e131a808cedd4f8bb542f4 100644 (file)
--- a/builtin-prune.c
+++ b/builtin-prune.c
save_commit_buffer = 0;
init_revisions(&revs, prefix);
- argc = parse_options(argc, argv, options, prune_usage, 0);
+ argc = parse_options(argc, argv, prefix, options, prune_usage, 0);
while (argc--) {
unsigned char sha1[20];
const char *name = *argv++;
diff --git a/builtin-push.c b/builtin-push.c
index 2eabcd3bdfb3f5d5705125a8f74d21d4ab1deafc..c869974013b5c1bb563d4f9b306820362545c9ea 100644 (file)
--- a/builtin-push.c
+++ b/builtin-push.c
OPT_END()
};
- argc = parse_options(argc, argv, options, push_usage, 0);
+ argc = parse_options(argc, argv, prefix, options, push_usage, 0);
if (tags)
add_refspec("refs/tags/*");
diff --git a/builtin-remote.c b/builtin-remote.c
index 71abf68404f5b260ba96208717d89e50e778dd36..13d5db168a8ec58ce6f99742fc35e71949559a6d 100644 (file)
--- a/builtin-remote.c
+++ b/builtin-remote.c
OPT_END()
};
- argc = parse_options(argc, argv, options, builtin_remote_usage, 0);
+ argc = parse_options(argc, argv, NULL, options, builtin_remote_usage,
+ 0);
if (argc < 2)
usage_with_options(builtin_remote_usage, options);
struct string_list info_list = { NULL, 0, 0, 0 };
struct show_info info;
- argc = parse_options(argc, argv, options, builtin_remote_usage, 0);
+ argc = parse_options(argc, argv, NULL, options, builtin_remote_usage,
+ 0);
if (argc < 1)
return show_all();
"delete refs/remotes/<name>/HEAD"),
OPT_END()
};
- argc = parse_options(argc, argv, options, builtin_remote_usage, 0);
+ argc = parse_options(argc, argv, NULL, options, builtin_remote_usage,
+ 0);
if (argc)
strbuf_addf(&buf, "refs/remotes/%s/HEAD", argv[0]);
OPT_END()
};
- argc = parse_options(argc, argv, options, builtin_remote_usage, 0);
+ argc = parse_options(argc, argv, NULL, options, builtin_remote_usage,
+ 0);
if (argc < 1)
usage_with_options(builtin_remote_usage, options);
OPT_END()
};
- argc = parse_options(argc, argv, options, builtin_remote_usage,
+ argc = parse_options(argc, argv, NULL, options, builtin_remote_usage,
PARSE_OPT_KEEP_ARGV0);
if (argc < 2) {
argc = 2;
};
int result;
- argc = parse_options(argc, argv, options, builtin_remote_usage,
+ argc = parse_options(argc, argv, prefix, options, builtin_remote_usage,
PARSE_OPT_STOP_AT_NON_OPTION);
if (argc < 1)
diff --git a/builtin-reset.c b/builtin-reset.c
index 7e7ebabaa865ebd749502774638efe7b6d26bec1..5fa1789d0c2b90ef9ee83d091b67292f2ff0db26 100644 (file)
--- a/builtin-reset.c
+++ b/builtin-reset.c
git_config(git_default_config, NULL);
- argc = parse_options(argc, argv, options, git_reset_usage,
+ argc = parse_options(argc, argv, prefix, options, git_reset_usage,
PARSE_OPT_KEEP_DASHDASH);
reflog_action = args_to_str(argv);
setenv("GIT_REFLOG_ACTION", reflog_action, 0);
diff --git a/builtin-rev-parse.c b/builtin-rev-parse.c
index c5b3d6e31bc899fe511f760de33870f20dc9766f..112d622cda6f74f9752627d9adf3a1cdb04851c3 100644 (file)
--- a/builtin-rev-parse.c
+++ b/builtin-rev-parse.c
int onb = 0, osz = 0, unb = 0, usz = 0;
strbuf_addstr(&parsed, "set --");
- argc = parse_options(argc, argv, parseopt_opts, parseopt_usage,
+ argc = parse_options(argc, argv, prefix, parseopt_opts, parseopt_usage,
PARSE_OPT_KEEP_DASHDASH);
if (argc < 1 || strcmp(argv[0], "--"))
usage_with_options(parseopt_usage, parseopt_opts);
/* put an OPT_END() */
ALLOC_GROW(opts, onb + 1, osz);
memset(opts + onb, 0, sizeof(opts[onb]));
- argc = parse_options(argc, argv, opts, usage,
+ argc = parse_options(argc, argv, prefix, opts, usage,
keep_dashdash ? PARSE_OPT_KEEP_DASHDASH : 0);
strbuf_addf(&parsed, " --");
diff --git a/builtin-revert.c b/builtin-revert.c
index 3f2614e1bbef009afadefff7d284225533db2a09..fa4752fd205ea6b3e122756d6c0640f059795737 100644 (file)
--- a/builtin-revert.c
+++ b/builtin-revert.c
OPT_END(),
};
- if (parse_options(argc, argv, options, usage_str, 0) != 1)
+ if (parse_options(argc, argv, NULL, options, usage_str, 0) != 1)
usage_with_options(usage_str, options);
arg = argv[0];
diff --git a/builtin-rm.c b/builtin-rm.c
index 269d60890ac6732f05b835e88bdb60a10bb3d441..0cc491271846214d73d55a4f528c8854e0460c8f 100644 (file)
--- a/builtin-rm.c
+++ b/builtin-rm.c
git_config(git_default_config, NULL);
- argc = parse_options(argc, argv, builtin_rm_options, builtin_rm_usage, 0);
+ argc = parse_options(argc, argv, prefix, builtin_rm_options,
+ builtin_rm_usage, 0);
if (!argc)
usage_with_options(builtin_rm_usage, builtin_rm_options);
diff --git a/builtin-shortlog.c b/builtin-shortlog.c
index b28091b4455db15e80841f2779ce0686d4f18826..6a3812ee18a2ca1bc251f67582ebaee3675d9af5 100644 (file)
--- a/builtin-shortlog.c
+++ b/builtin-shortlog.c
git_config(git_default_config, NULL);
shortlog_init(&log);
init_revisions(&rev, prefix);
- 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 (;;) {
diff --git a/builtin-show-branch.c b/builtin-show-branch.c
index b1affd2ffbbff955d24ed0a32b2d89d1ae7fe024..94338119569b6af85c9d121daa2134818f7d321e 100644 (file)
--- a/builtin-show-branch.c
+++ b/builtin-show-branch.c
av = default_arg - 1; /* ick; we would not address av[0] */
}
- ac = parse_options(ac, av, builtin_show_branch_options,
+ ac = parse_options(ac, av, prefix, builtin_show_branch_options,
show_branch_usage, PARSE_OPT_STOP_AT_NON_OPTION);
if (all_heads)
all_remotes = 1;
diff --git a/builtin-symbolic-ref.c b/builtin-symbolic-ref.c
index 6ae6bcc0e8d02d9af8a81a7d694c0bfd2c6c0514..ca855a5eb239f4dadccd53369e38db4e78b1d13f 100644 (file)
--- a/builtin-symbolic-ref.c
+++ b/builtin-symbolic-ref.c
};
git_config(git_default_config, NULL);
- argc = parse_options(argc, argv, options, git_symbolic_ref_usage, 0);
+ argc = parse_options(argc, argv, prefix, options,
+ git_symbolic_ref_usage, 0);
if (msg &&!*msg)
die("Refusing to perform update with empty message");
switch (argc) {
diff --git a/builtin-tag.c b/builtin-tag.c
index e54443009420d98dc281285e997b32f2a263b996..6e8b464109af51718eb3b83718af3d6ffaab137b 100644 (file)
--- a/builtin-tag.c
+++ b/builtin-tag.c
git_config(git_tag_config, NULL);
- argc = parse_options(argc, argv, options, git_tag_usage, 0);
+ argc = parse_options(argc, argv, prefix, options, git_tag_usage, 0);
msgfile = parse_options_fix_filename(prefix, msgfile);
if (keyid) {
diff --git a/builtin-update-ref.c b/builtin-update-ref.c
index 378dc1b7a6bb4d56d301a34a4d44dae2f9a37e44..76ba1d5881b3cddc527bd363dec340c83dde605f 100644 (file)
--- a/builtin-update-ref.c
+++ b/builtin-update-ref.c
};
git_config(git_default_config, NULL);
- argc = parse_options(argc, argv, options, git_update_ref_usage, 0);
+ argc = parse_options(argc, argv, prefix, options, git_update_ref_usage,
+ 0);
if (msg && !*msg)
die("Refusing to perform update with empty message.");
diff --git a/hash-object.c b/hash-object.c
index ebb3bedb074202a29e2356845012bd1ffae0dc19..47cf43c3cdd2bcd7638360a130fc8ef04ce132e9 100644 (file)
--- a/hash-object.c
+++ b/hash-object.c
git_extract_argv0_path(argv[0]);
- argc = parse_options(argc, argv, hash_object_options, hash_object_usage, 0);
+ argc = parse_options(argc, argv, NULL, hash_object_options,
+ hash_object_usage, 0);
if (write_object) {
prefix = setup_git_directory();
diff --git a/parse-options.c b/parse-options.c
index 1d25b94c72b3fc52eabbdc31a61e43e404ddb303..be1800d7b48bf07bd3b01395f6ea6fed40bddb37 100644 (file)
--- a/parse-options.c
+++ b/parse-options.c
}
void parse_options_start(struct parse_opt_ctx_t *ctx,
- int argc, const char **argv, int flags)
+ int argc, const char **argv, const char *prefix,
+ int flags)
{
memset(ctx, 0, sizeof(*ctx));
ctx->argc = argc - 1;
ctx->argv = argv + 1;
ctx->out = argv;
+ ctx->prefix = prefix;
ctx->cpidx = ((flags & PARSE_OPT_KEEP_ARGV0) != 0);
ctx->flags = flags;
if ((flags & PARSE_OPT_KEEP_UNKNOWN) &&
return ctx->cpidx + ctx->argc;
}
-int parse_options(int argc, const char **argv, const struct option *options,
- const char * const usagestr[], int flags)
+int parse_options(int argc, const char **argv, const char *prefix,
+ const struct option *options, const char * const usagestr[],
+ int flags)
{
struct parse_opt_ctx_t ctx;
- parse_options_start(&ctx, argc, argv, flags);
+ parse_options_start(&ctx, argc, argv, prefix, flags);
switch (parse_options_step(&ctx, options, usagestr)) {
case PARSE_OPT_HELP:
exit(129);
diff --git a/parse-options.h b/parse-options.h
index fe41ab2c67024b91794c483c2436e33e205f5f62..f652c0f3c735a213ac2cc169b11025fc40987997 100644 (file)
--- a/parse-options.h
+++ b/parse-options.h
* non-option arguments in argv[].
* Returns the number of arguments left in argv[].
*/
-extern int parse_options(int argc, const char **argv,
+extern int parse_options(int argc, const char **argv, const char *prefix,
const struct option *options,
const char * const usagestr[], int flags);
int argc, cpidx;
const char *opt;
int flags;
+ const char *prefix;
};
extern int parse_options_usage(const char * const *usagestr,
const struct option *opts);
extern void parse_options_start(struct parse_opt_ctx_t *ctx,
- int argc, const char **argv, int flags);
+ int argc, const char **argv, const char *prefix,
+ int flags);
extern int parse_options_step(struct parse_opt_ctx_t *ctx,
const struct option *options,
diff --git a/test-parse-options.c b/test-parse-options.c
index e0669dcb41d1d779f274e1ff785352e284953b14..da3d6581d307763d05fa4b8492ade424a85f50f1 100644 (file)
--- a/test-parse-options.c
+++ b/test-parse-options.c
};
int i;
- argc = parse_options(argc, argv, options, usage, 0);
+ argc = parse_options(argc, argv, NULL, options, usage, 0);
printf("boolean: %d\n", boolean);
printf("integer: %u\n", integer);