From: Derrick Stolee via GitGitGadget Date: Tue, 07 Jul 2020 14:21:20 GMT Subject: [PATCH 06/21] maintenance: add --quiet option Message-ID: <018a9331e204fd6b1b92f5b53f3f373fa9e23bc2.1594131695.git.gitgitgadget@gmail.com> In-Reply-To: From: Derrick Stolee Maintenance activities are commonly used as steps in larger scripts. Providing a '--quiet' option allows those scripts to be less noisy when run on a terminal window. Turn this mode on by default when stderr is not a terminal. Pipe the option to the 'git gc' child process. Signed-off-by: Derrick Stolee --- Documentation/git-maintenance.txt | 3 +++ builtin/gc.c | 7 +++++++ t/t7900-maintenance.sh | 8 +++++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Documentation/git-maintenance.txt b/Documentation/git-maintenance.txt index 34cd2b4417..089fa4cedc 100644 --- a/Documentation/git-maintenance.txt +++ b/Documentation/git-maintenance.txt @@ -52,6 +52,9 @@ OPTIONS in the `gc.auto` config setting, or when the number of pack-files exceeds the `gc.autoPackLimit` config setting. +--quiet:: + Do not report progress or other information over `stderr`. + GIT --- Part of the linkgit:git[1] suite diff --git a/builtin/gc.c b/builtin/gc.c index 07cc5f46ae..3881a99e9d 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -712,6 +712,7 @@ static const char * const builtin_maintenance_usage[] = { struct maintenance_opts { int auto_flag; + int quiet; } opts; static int maintenance_task_gc(struct repository *r) @@ -723,6 +724,8 @@ static int maintenance_task_gc(struct repository *r) if (opts.auto_flag) argv_array_pushl(&cmd, "--auto", NULL); + if (opts.quiet) + argv_array_pushl(&cmd, "--quiet", NULL); close_object_store(r->objects); result = run_command_v_opt(cmd.argv, RUN_GIT_CMD); @@ -743,6 +746,8 @@ int cmd_maintenance(int argc, const char **argv, const char *prefix) static struct option builtin_maintenance_options[] = { OPT_BOOL(0, "auto", &opts.auto_flag, N_("run tasks based on the state of the repository")), + OPT_BOOL(0, "quiet", &opts.quiet, + N_("do not report progress or other information over stderr")), OPT_END() }; @@ -752,6 +757,8 @@ int cmd_maintenance(int argc, const char **argv, const char *prefix) usage_with_options(builtin_maintenance_usage, builtin_maintenance_options); + opts.quiet = !isatty(2); + argc = parse_options(argc, argv, prefix, builtin_maintenance_options, builtin_maintenance_usage, diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh index d00641c4dd..e4e4036e50 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -12,11 +12,13 @@ test_expect_success 'help text' ' test_i18ngrep "usage: git maintenance run" err ' -test_expect_success 'gc [--auto]' ' - GIT_TRACE2_EVENT="$(pwd)/run-no-auto.txt" git maintenance run && +test_expect_success 'gc [--auto|--quiet]' ' + GIT_TRACE2_EVENT="$(pwd)/run-no-auto.txt" git maintenance run --no-quiet && GIT_TRACE2_EVENT="$(pwd)/run-auto.txt" git maintenance run --auto && + GIT_TRACE2_EVENT="$(pwd)/run-quiet.txt" git maintenance run --quiet && grep ",\"gc\"]" run-no-auto.txt && - grep ",\"gc\",\"--auto\"]" run-auto.txt + grep ",\"gc\",\"--auto\"" run-auto.txt && + grep ",\"gc\",\"--quiet\"" run-quiet.txt ' test_done -- gitgitgadget