repack: make '--quiet' disable progress

While testing some ideas in 'git repack', I ran it with '--quiet' and discovered that some progress output was still shown. Specifically, the output for writing the multi-pack-index showed the progress. The 'show_progress' variable in cmd_repack() is initialized with isatty(2) and is not modified at all by the '--quiet' flag. The '--quiet' flag modifies the po_args.quiet option which is translated into a '--quiet' flag for the 'git pack-objects' child process. However, 'show_progress' is used to directly send progress information to the multi-pack-index writing logic which does not use a child process. The fix here is to modify 'show_progress' to be false if po_opts.quiet is true, and isatty(2) otherwise. This new expectation simplifies a later condition that checks both. Update the documentation to make it clear that '-q' will disable all progress in addition to ensuring the 'git pack-objects' child process will receive the flag. Use 'test_terminal' to check that this works to get around the isatty(2) check. Helped-by: Jeff King <peff@peff.net> Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Dec 20, 2021 at 14:48 UTC 47ca93d0710c114b61b3079d3b88d2d7528f5666
3 files changed +14 -4
Documentation/git-repack.txt
+3 -2
@@ -76,8 +76,9 @@ to the new separate pack will be written.
76 linkgit:git-pack-objects[1].
77
78 -q::
79 - Pass the `-q` option to 'git pack-objects'. See
80 - linkgit:git-pack-objects[1].
79 +--quiet::
80 + Show no progress over the standard error stream and pass the `-q`
81 + option to 'git pack-objects'. See linkgit:git-pack-objects[1].
82
83 -n::
84 Do not update the server information with
builtin/repack.c
+4 -2
@@ -610,7 +610,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
610 struct tempfile *refs_snapshot = NULL;
611 int i, ext, ret;
612 FILE *out;
613 - int show_progress = isatty(2);
613 + int show_progress;
614
615 /* variables to be filled by option parsing */
616 int pack_everything = 0;
@@ -723,6 +723,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
723
724 prepare_pack_objects(&cmd, &po_args);
725
726 + show_progress = !po_args.quiet && isatty(2);
727 +
728 strvec_push(&cmd.args, "--keep-true-parents");
729 if (!pack_kept_objects)
730 strvec_push(&cmd.args, "--honor-pack-keep");
@@ -924,7 +926,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
926 }
927 strbuf_release(&buf);
928 }
927 - if (!po_args.quiet && show_progress)
929 + if (show_progress)
930 opts |= PRUNE_PACKED_VERBOSE;
931 prune_packed_objects(opts);
932
t/t7700-repack.sh
+7
@@ -5,6 +5,7 @@ test_description='git repack works correctly'
5 . ./test-lib.sh
6 . "${TEST_DIRECTORY}/lib-bitmap.sh"
7 . "${TEST_DIRECTORY}/lib-midx.sh"
8 +. "${TEST_DIRECTORY}/lib-terminal.sh"
9
10 commit_and_pack () {
11 test_commit "$@" 1>&2 &&
@@ -378,4 +379,10 @@ test_expect_success '--write-midx -b packs non-kept objects' '
379 test_subcommand_inexact git pack-objects --honor-pack-keep <trace.txt
380 '
381
382 +test_expect_success TTY '--quiet disables progress' '
383 + test_terminal env GIT_PROGRESS_DELAY=0 \
384 + git -C midx repack -ad --quiet --write-midx 2>stderr &&
385 + test_must_be_empty stderr
386 +'
387 +
388 test_done