git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 2/2] repack: make '--quiet' disable progress

From
Derrick Stolee via GitGitGadget <gitgitgadget@gmail.com>
Date
Dec 20, 2021, 14:48 UTC
Message-ID
<41260bf0829970eeb27bec2cb41cabeffa54dabb.1640011691.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1098.v2.git.1640011691.gitgitgadget@gmail.com>
From: Derrick Stolee <dstolee@microsoft.com>

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>
---
 Documentation/git-repack.txt | 5 +++--
 builtin/repack.c             | 6 ++++--
 t/t7700-repack.sh            | 7 +++++++
 3 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/Documentation/git-repack.txt b/Documentation/git-repack.txt
index 7183fb498f4..ee30edc178a 100644
--- a/Documentation/git-repack.txt
+++ b/Documentation/git-repack.txt
@@ -76,8 +76,9 @@ to the new separate pack will be written.
 	linkgit:git-pack-objects[1].
 
 -q::
-	Pass the `-q` option to 'git pack-objects'. See
-	linkgit:git-pack-objects[1].
+--quiet::
+	Show no progress over the standard error stream and pass the `-q`
+	option to 'git pack-objects'. See linkgit:git-pack-objects[1].
 
 -n::
 	Do not update the server information with
diff --git a/builtin/repack.c b/builtin/repack.c
index 1f128b7c90b..c393a5db774 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -612,7 +612,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
 	struct tempfile *refs_snapshot = NULL;
 	int i, ext, ret;
 	FILE *out;
-	int show_progress = isatty(2);
+	int show_progress;
 
 	/* variables to be filled by option parsing */
 	int pack_everything = 0;
@@ -725,6 +725,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
 
 	prepare_pack_objects(&cmd, &po_args);
 
+	show_progress = !po_args.quiet && isatty(2);
+
 	strvec_push(&cmd.args, "--keep-true-parents");
 	if (!pack_kept_objects)
 		strvec_push(&cmd.args, "--honor-pack-keep");
@@ -926,7 +928,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
 			}
 			strbuf_release(&buf);
 		}
-		if (!po_args.quiet && show_progress)
+		if (show_progress)
 			opts |= PRUNE_PACKED_VERBOSE;
 		prune_packed_objects(opts);
 
diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index 63c9a247f57..fe2b493d0ee 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -5,6 +5,7 @@ test_description='git repack works correctly'
 . ./test-lib.sh
 . "${TEST_DIRECTORY}/lib-bitmap.sh"
 . "${TEST_DIRECTORY}/lib-midx.sh"
+. "${TEST_DIRECTORY}/lib-terminal.sh"
 
 commit_and_pack () {
 	test_commit "$@" 1>&2 &&
@@ -378,4 +379,10 @@ test_expect_success '--write-midx -b packs non-kept objects' '
 	test_subcommand_inexact git pack-objects --honor-pack-keep <trace.txt
 '
 
+test_expect_success TTY '--quiet disables progress' '
+	test_terminal env GIT_PROGRESS_DELAY=0 \
+		git -C midx repack -ad --quiet --write-midx 2>stderr &&
+	test_must_be_empty stderr
+'
+
 test_done
-- 
gitgitgadget
Previous: Derrick Stolee via GitGitGadgetNext: Derrick Stolee via GitGitGadget
Message 15 of 17 in “Two small 'git repack' fixes”
  1. 0/2 Two small 'git repack' fixesDerrick Stolee via GitGitGadget, Dec 17, 2021
  2. 1/2 repack: respect kept objects with '--write-midx -b'Derrick Stolee via GitGitGadget, Dec 17, 2021
  3. Jeff KingDec 17, 2021
  4. Derrick StoleeDec 20, 2021
  5. Jeff KingDec 20, 2021
  6. Ævar Arnfjörð BjarmasonDec 18, 2021
  7. 2/2 repack: make '--quiet' disable progressDerrick Stolee via GitGitGadget, Dec 17, 2021
  8. Jeff KingDec 17, 2021
  9. Derrick StoleeDec 20, 2021
  10. Jeff KingDec 20, 2021
  11. Derrick StoleeDec 20, 2021
  12. Ævar Arnfjörð BjarmasonDec 18, 2021
  13. Derrick StoleeDec 20, 2021
  14. 0/2 Two small 'git repack' fixesDerrick Stolee via GitGitGadget, Dec 20, 2021
  15. 2/2 repack: make '--quiet' disable progressDerrick Stolee via GitGitGadget, Dec 20, 2021
  16. 1/2 repack: respect kept objects with '--write-midx -b'Derrick Stolee via GitGitGadget, Dec 20, 2021
  17. Ævar Arnfjörð BjarmasonDec 20, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.