Skip to content

Commit 47ca93d

Browse files
derrickstoleegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e4d0c11 commit 47ca93d

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

Documentation/git-repack.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ to the new separate pack will be written.
7676
linkgit:git-pack-objects[1].
7777

7878
-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].
8182

8283
-n::
8384
Do not update the server information with

builtin/repack.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
610610
struct tempfile *refs_snapshot = NULL;
611611
int i, ext, ret;
612612
FILE *out;
613-
int show_progress = isatty(2);
613+
int show_progress;
614614

615615
/* variables to be filled by option parsing */
616616
int pack_everything = 0;
@@ -723,6 +723,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
723723

724724
prepare_pack_objects(&cmd, &po_args);
725725

726+
show_progress = !po_args.quiet && isatty(2);
727+
726728
strvec_push(&cmd.args, "--keep-true-parents");
727729
if (!pack_kept_objects)
728730
strvec_push(&cmd.args, "--honor-pack-keep");
@@ -924,7 +926,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
924926
}
925927
strbuf_release(&buf);
926928
}
927-
if (!po_args.quiet && show_progress)
929+
if (show_progress)
928930
opts |= PRUNE_PACKED_VERBOSE;
929931
prune_packed_objects(opts);
930932

t/t7700-repack.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ test_description='git repack works correctly'
55
. ./test-lib.sh
66
. "${TEST_DIRECTORY}/lib-bitmap.sh"
77
. "${TEST_DIRECTORY}/lib-midx.sh"
8+
. "${TEST_DIRECTORY}/lib-terminal.sh"
89

910
commit_and_pack () {
1011
test_commit "$@" 1>&2 &&
@@ -378,4 +379,10 @@ test_expect_success '--write-midx -b packs non-kept objects' '
378379
test_subcommand_inexact git pack-objects --honor-pack-keep <trace.txt
379380
'
380381

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+
381388
test_done

0 commit comments

Comments
 (0)