Merge branch 'rs/bundle-parseopt-cleanup' into next

Code clean-up.

* rs/bundle-parseopt-cleanup:
  bundle: use OPT_PASSTHRU_ARGV
This commit is contained in:
Junio C Hamano
2023-08-01 10:56:03 -07:00
2 changed files with 23 additions and 23 deletions

View File

@ -68,42 +68,36 @@ static int parse_options_cmd_bundle(int argc,
} }
static int cmd_bundle_create(int argc, const char **argv, const char *prefix) { static int cmd_bundle_create(int argc, const char **argv, const char *prefix) {
int all_progress_implied = 1; struct strvec pack_opts = STRVEC_INIT;
int progress = isatty(STDERR_FILENO);
struct strvec pack_opts;
int version = -1; int version = -1;
int ret; int ret;
struct option options[] = { struct option options[] = {
OPT_SET_INT('q', "quiet", &progress, OPT_PASSTHRU_ARGV('q', "quiet", &pack_opts, NULL,
N_("do not show progress meter"), 0), N_("do not show progress meter"),
OPT_SET_INT(0, "progress", &progress, PARSE_OPT_NOARG),
N_("show progress meter"), 1), OPT_PASSTHRU_ARGV(0, "progress", &pack_opts, NULL,
OPT_SET_INT_F(0, "all-progress", &progress, N_("show progress meter"),
N_("historical; same as --progress"), 2, PARSE_OPT_NOARG),
PARSE_OPT_HIDDEN), OPT_PASSTHRU_ARGV(0, "all-progress", &pack_opts, NULL,
OPT_HIDDEN_BOOL(0, "all-progress-implied", N_("historical; same as --progress"),
&all_progress_implied, PARSE_OPT_NOARG | PARSE_OPT_HIDDEN),
N_("historical; does nothing")), OPT_PASSTHRU_ARGV(0, "all-progress-implied", &pack_opts, NULL,
N_("historical; does nothing"),
PARSE_OPT_NOARG | PARSE_OPT_HIDDEN),
OPT_INTEGER(0, "version", &version, OPT_INTEGER(0, "version", &version,
N_("specify bundle format version")), N_("specify bundle format version")),
OPT_END() OPT_END()
}; };
char *bundle_file; char *bundle_file;
if (isatty(STDERR_FILENO))
strvec_push(&pack_opts, "--progress");
strvec_push(&pack_opts, "--all-progress-implied");
argc = parse_options_cmd_bundle(argc, argv, prefix, argc = parse_options_cmd_bundle(argc, argv, prefix,
builtin_bundle_create_usage, options, &bundle_file); builtin_bundle_create_usage, options, &bundle_file);
/* bundle internals use argv[1] as further parameters */ /* bundle internals use argv[1] as further parameters */
strvec_init(&pack_opts);
if (progress == 0)
strvec_push(&pack_opts, "--quiet");
else if (progress == 1)
strvec_push(&pack_opts, "--progress");
else if (progress == 2)
strvec_push(&pack_opts, "--all-progress");
if (progress && all_progress_implied)
strvec_push(&pack_opts, "--all-progress-implied");
if (!startup_info->have_repository) if (!startup_info->have_repository)
die(_("Need a repository to create a bundle.")); die(_("Need a repository to create a bundle."));
ret = !!create_bundle(the_repository, bundle_file, argc, argv, &pack_opts, version); ret = !!create_bundle(the_repository, bundle_file, argc, argv, &pack_opts, version);

View File

@ -619,6 +619,12 @@ test_expect_success TTY 'create --quiet disables all bundle progress' '
test_must_be_empty err test_must_be_empty err
' '
test_expect_success 'bundle progress with --no-quiet' '
GIT_PROGRESS_DELAY=0 \
git bundle create --no-quiet out.bundle --all 2>err &&
grep "%" err
'
test_expect_success 'read bundle over stdin' ' test_expect_success 'read bundle over stdin' '
git bundle create some.bundle HEAD && git bundle create some.bundle HEAD &&