mirror of
https://github.com/git/git.git
synced 2026-08-09 09:34:14 +00:00
fast-import: use parse_options() for command line options
Previous commits have started to use the parse-options API to display
output from `git fast-import -h` and `git fast-import --help-all` and
to prepare for parsing the command line options using this API.
Let's now actually use the API to parse command line options.
This brings a number of changes that are mostly beneficial:
- The `--alias`, `--get-mark`, `--cat-blob`, `--ls` and `--notes`
options are no longer accepted on the command line. They were
previously accepted as no-ops because parse_argv() fell through to
parse_one_feature(). They are not documented in the OPTIONS section
and are only meaningful as in-stream feature assertions, so
accepting them on the command line was an accident of code sharing
dating back to 9c8398f0c9 (fast-import: add option command,
2009-12-04).
- Abbreviated options like `--dep=5` now work since parse_options()
allows unambiguous prefixes.
- As `--cat-blob` is an abbreviation of `--cat-blob-fd`, using the
former on the command line will fail with "option `cat-blob-fd'
requires a value" unlike the other four options that are not
accepted anymore on the command line (see above).
- The error messages for some options might differ a bit.
- The code is shorter and more standard.
Note that parse_one_feature() is now always called with its
`from_stream` argument set to 1, but the code simplifications that
can be made are left for a following clean-up commit.
Signed-off-by: Christian Couder <christian.couder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
873854d8d4
commit
79e3430248
@@ -3945,31 +3945,11 @@ static const char *const fast_import_usage[] = {
|
||||
|
||||
static void parse_argv(struct fast_import_state *state)
|
||||
{
|
||||
unsigned int i;
|
||||
int argc = parse_options(state->argc, state->argv, state->prefix,
|
||||
state->option, fast_import_usage,
|
||||
PARSE_OPT_KEEP_ARGV0);
|
||||
|
||||
for (i = 1; i < state->argc; i++) {
|
||||
const char *a = state->argv[i];
|
||||
|
||||
if (*a != '-' || !strcmp(a, "--"))
|
||||
break;
|
||||
|
||||
if (!skip_prefix(a, "--", &a))
|
||||
die(_("unknown option %s"), a);
|
||||
|
||||
if (parse_one_option(state, a))
|
||||
continue;
|
||||
|
||||
if (parse_one_feature(state, a, 0))
|
||||
continue;
|
||||
|
||||
if (skip_prefix(a, "cat-blob-fd=", &a)) {
|
||||
option_cat_blob_fd(state, a);
|
||||
continue;
|
||||
}
|
||||
|
||||
die(_("unknown option --%s"), a);
|
||||
}
|
||||
if (i != state->argc)
|
||||
if (argc > 1)
|
||||
usage_with_options(fast_import_usage, state->option);
|
||||
|
||||
state->seen_data_command = 1;
|
||||
@@ -4105,11 +4085,6 @@ int cmd_fast_import(int argc,
|
||||
{
|
||||
struct fast_import_state state;
|
||||
|
||||
/*
|
||||
* NEEDSWORK: For now this is used only to render
|
||||
* `-h`/`--help-all` usage messages. The actual parsing is
|
||||
* done by parse_one_option()/parse_one_feature().
|
||||
*/
|
||||
struct option fast_import_options[] = {
|
||||
OPT_GROUP(N_("Common")),
|
||||
OPT_CALLBACK_F(0, "date-format", NULL, N_("fmt"),
|
||||
|
||||
@@ -2827,6 +2827,13 @@ test_expect_success 'R: unknown commandline options are rejected' '\
|
||||
test_must_fail git fast-import --non-existing-option < /dev/null
|
||||
'
|
||||
|
||||
test_expect_success 'R: feature-only names are rejected on the command line' '
|
||||
for opt in --alias --get-mark --ls --notes
|
||||
do
|
||||
test_must_fail git fast-import "$opt" </dev/null || return 1
|
||||
done
|
||||
'
|
||||
|
||||
test_expect_success 'R: die on invalid option argument' '
|
||||
echo "option git active-branches=-5" |
|
||||
test_must_fail git fast-import &&
|
||||
|
||||
Reference in New Issue
Block a user