bundle: use OPT_PASSTHRU_ARGV

"git bundle" passes the progress control options to "git pack-objects" by parsing and then recreating them explicitly. Simplify that process by using OPT_PASSTHRU_ARGV instead. This also fixes --no-quiet, which has been doing the same as --quiet since its introduction by 79862b6b77 (bundle-create: progress output control, 2019-11-10) because it had been defined using OPT_SET_INT with a value of 0, which sets 0 when negated as well. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Jul 29, 2023 at 22:40 UTC d089a06421c86d120f50f05020ca6b833b068dcb
2 files changed +23 -23
builtin/bundle.c
+17 -23
@@ -69,42 +69,36 @@ static int parse_options_cmd_bundle(int argc,
69 }
70
71 static int cmd_bundle_create(int argc, const char **argv, const char *prefix) {
72 - int all_progress_implied = 1;
73 - int progress = isatty(STDERR_FILENO);
74 - struct strvec pack_opts;
72 + struct strvec pack_opts = STRVEC_INIT;
73 int version = -1;
74 int ret;
75 struct option options[] = {
78 - OPT_SET_INT('q', "quiet", &progress,
79 - N_("do not show progress meter"), 0),
80 - OPT_SET_INT(0, "progress", &progress,
81 - N_("show progress meter"), 1),
82 - OPT_SET_INT_F(0, "all-progress", &progress,
83 - N_("historical; same as --progress"), 2,
84 - PARSE_OPT_HIDDEN),
85 - OPT_HIDDEN_BOOL(0, "all-progress-implied",
86 - &all_progress_implied,
87 - N_("historical; does nothing")),
76 + OPT_PASSTHRU_ARGV('q', "quiet", &pack_opts, NULL,
77 + N_("do not show progress meter"),
78 + PARSE_OPT_NOARG),
79 + OPT_PASSTHRU_ARGV(0, "progress", &pack_opts, NULL,
80 + N_("show progress meter"),
81 + PARSE_OPT_NOARG),
82 + OPT_PASSTHRU_ARGV(0, "all-progress", &pack_opts, NULL,
83 + N_("historical; same as --progress"),
84 + PARSE_OPT_NOARG | PARSE_OPT_HIDDEN),
85 + OPT_PASSTHRU_ARGV(0, "all-progress-implied", &pack_opts, NULL,
86 + N_("historical; does nothing"),
87 + PARSE_OPT_NOARG | PARSE_OPT_HIDDEN),
88 OPT_INTEGER(0, "version", &version,
89 N_("specify bundle format version")),
90 OPT_END()
91 };
92 char *bundle_file;
93
94 + if (isatty(STDERR_FILENO))
95 + strvec_push(&pack_opts, "--progress");
96 + strvec_push(&pack_opts, "--all-progress-implied");
97 +
98 argc = parse_options_cmd_bundle(argc, argv, prefix,
99 builtin_bundle_create_usage, options, &bundle_file);
100 /* bundle internals use argv[1] as further parameters */
101
98 - strvec_init(&pack_opts);
99 - if (progress == 0)
100 - strvec_push(&pack_opts, "--quiet");
101 - else if (progress == 1)
102 - strvec_push(&pack_opts, "--progress");
103 - else if (progress == 2)
104 - strvec_push(&pack_opts, "--all-progress");
105 - if (progress && all_progress_implied)
106 - strvec_push(&pack_opts, "--all-progress-implied");
107 -
102 if (!startup_info->have_repository)
103 die(_("Need a repository to create a bundle."));
104 ret = !!create_bundle(the_repository, bundle_file, argc, argv, &pack_opts, version);
t/t6020-bundle-misc.sh
+6
@@ -619,6 +619,12 @@ test_expect_success TTY 'create --quiet disables all bundle progress' '
619 test_must_be_empty err
620 '
621
622 +test_expect_success 'bundle progress with --no-quiet' '
623 + GIT_PROGRESS_DELAY=0 \
624 + git bundle create --no-quiet out.bundle --all 2>err &&
625 + grep "%" err
626 +'
627 +
628 test_expect_success 'read bundle over stdin' '
629 git bundle create some.bundle HEAD &&
630