maintenance: add --quiet option
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 <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Derrick Stolee committed
Sep 17, 2020 at 18:11 UTC
3ddaad0e06035a752c9010dcd5094b37262080fb
3 files changed
+23
-6
Documentation/git-maintenance.txt
+3
@@ -52,6 +52,9 @@ OPTIONS
52
in the `gc.auto` config setting, or when the number of pack-files
53
exceeds the `gc.autoPackLimit` config setting.
54
55
+--quiet::
56
+ Do not report progress or other information over `stderr`.
57
+
58
GIT
59
---
60
Part of the linkgit:git[1] suite
builtin/gc.c
+10
-1
@@ -701,12 +701,13 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
701
}
702
703
static const char * const builtin_maintenance_run_usage[] = {
704
- N_("git maintenance run [--auto]"),
704
+ N_("git maintenance run [--auto] [--[no-]quiet]"),
705
NULL
706
};
707
708
struct maintenance_run_opts {
709
int auto_flag;
710
+ int quiet;
711
};
712
713
static int maintenance_task_gc(struct maintenance_run_opts *opts)
@@ -718,6 +719,10 @@ static int maintenance_task_gc(struct maintenance_run_opts *opts)
719
720
if (opts->auto_flag)
721
strvec_push(&child.args, "--auto");
722
+ if (opts->quiet)
723
+ strvec_push(&child.args, "--quiet");
724
+ else
725
+ strvec_push(&child.args, "--no-quiet");
726
727
close_object_store(the_repository->objects);
728
return run_command(&child);
@@ -729,10 +734,14 @@ static int maintenance_run(int argc, const char **argv, const char *prefix)
734
struct option builtin_maintenance_run_options[] = {
735
OPT_BOOL(0, "auto", &opts.auto_flag,
736
N_("run tasks based on the state of the repository")),
737
+ OPT_BOOL(0, "quiet", &opts.quiet,
738
+ N_("do not report progress or other information over stderr")),
739
OPT_END()
740
};
741
memset(&opts, 0, sizeof(opts));
742
743
+ opts.quiet = !isatty(2);
744
+
745
argc = parse_options(argc, argv, prefix,
746
builtin_maintenance_run_options,
747
builtin_maintenance_run_usage,
t/t7900-maintenance.sh
+10
-5
@@ -13,11 +13,16 @@ test_expect_success 'help text' '
13
test_i18ngrep "usage: git maintenance" err
14
'
15
16
-test_expect_success 'run [--auto]' '
17
- GIT_TRACE2_EVENT="$(pwd)/run-no-auto.txt" git maintenance run &&
18
- GIT_TRACE2_EVENT="$(pwd)/run-auto.txt" git maintenance run --auto &&
19
- test_subcommand git gc <run-no-auto.txt &&
20
- test_subcommand git gc --auto <run-auto.txt
16
+test_expect_success 'run [--auto|--quiet]' '
17
+ GIT_TRACE2_EVENT="$(pwd)/run-no-auto.txt" \
18
+ git maintenance run 2>/dev/null &&
19
+ GIT_TRACE2_EVENT="$(pwd)/run-auto.txt" \
20
+ git maintenance run --auto 2>/dev/null &&
21
+ GIT_TRACE2_EVENT="$(pwd)/run-no-quiet.txt" \
22
+ git maintenance run --no-quiet 2>/dev/null &&
23
+ test_subcommand git gc --quiet <run-no-auto.txt &&
24
+ test_subcommand git gc --auto --quiet <run-auto.txt &&
25
+ test_subcommand git gc --no-quiet <run-no-quiet.txt
26
'
27
28
test_done