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>
This commit is contained in:
parent
2057d75038
commit
3ddaad0e06
@ -52,6 +52,9 @@ OPTIONS
|
|||||||
in the `gc.auto` config setting, or when the number of pack-files
|
in the `gc.auto` config setting, or when the number of pack-files
|
||||||
exceeds the `gc.autoPackLimit` config setting.
|
exceeds the `gc.autoPackLimit` config setting.
|
||||||
|
|
||||||
|
--quiet::
|
||||||
|
Do not report progress or other information over `stderr`.
|
||||||
|
|
||||||
GIT
|
GIT
|
||||||
---
|
---
|
||||||
Part of the linkgit:git[1] suite
|
Part of the linkgit:git[1] suite
|
||||||
|
11
builtin/gc.c
11
builtin/gc.c
@ -701,12 +701,13 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const char * const builtin_maintenance_run_usage[] = {
|
static const char * const builtin_maintenance_run_usage[] = {
|
||||||
N_("git maintenance run [--auto]"),
|
N_("git maintenance run [--auto] [--[no-]quiet]"),
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
struct maintenance_run_opts {
|
struct maintenance_run_opts {
|
||||||
int auto_flag;
|
int auto_flag;
|
||||||
|
int quiet;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int maintenance_task_gc(struct maintenance_run_opts *opts)
|
static int maintenance_task_gc(struct maintenance_run_opts *opts)
|
||||||
@ -718,6 +719,10 @@ static int maintenance_task_gc(struct maintenance_run_opts *opts)
|
|||||||
|
|
||||||
if (opts->auto_flag)
|
if (opts->auto_flag)
|
||||||
strvec_push(&child.args, "--auto");
|
strvec_push(&child.args, "--auto");
|
||||||
|
if (opts->quiet)
|
||||||
|
strvec_push(&child.args, "--quiet");
|
||||||
|
else
|
||||||
|
strvec_push(&child.args, "--no-quiet");
|
||||||
|
|
||||||
close_object_store(the_repository->objects);
|
close_object_store(the_repository->objects);
|
||||||
return run_command(&child);
|
return run_command(&child);
|
||||||
@ -729,10 +734,14 @@ static int maintenance_run(int argc, const char **argv, const char *prefix)
|
|||||||
struct option builtin_maintenance_run_options[] = {
|
struct option builtin_maintenance_run_options[] = {
|
||||||
OPT_BOOL(0, "auto", &opts.auto_flag,
|
OPT_BOOL(0, "auto", &opts.auto_flag,
|
||||||
N_("run tasks based on the state of the repository")),
|
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()
|
OPT_END()
|
||||||
};
|
};
|
||||||
memset(&opts, 0, sizeof(opts));
|
memset(&opts, 0, sizeof(opts));
|
||||||
|
|
||||||
|
opts.quiet = !isatty(2);
|
||||||
|
|
||||||
argc = parse_options(argc, argv, prefix,
|
argc = parse_options(argc, argv, prefix,
|
||||||
builtin_maintenance_run_options,
|
builtin_maintenance_run_options,
|
||||||
builtin_maintenance_run_usage,
|
builtin_maintenance_run_usage,
|
||||||
|
@ -13,11 +13,16 @@ test_expect_success 'help text' '
|
|||||||
test_i18ngrep "usage: git maintenance" err
|
test_i18ngrep "usage: git maintenance" err
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'run [--auto]' '
|
test_expect_success 'run [--auto|--quiet]' '
|
||||||
GIT_TRACE2_EVENT="$(pwd)/run-no-auto.txt" git maintenance run &&
|
GIT_TRACE2_EVENT="$(pwd)/run-no-auto.txt" \
|
||||||
GIT_TRACE2_EVENT="$(pwd)/run-auto.txt" git maintenance run --auto &&
|
git maintenance run 2>/dev/null &&
|
||||||
test_subcommand git gc <run-no-auto.txt &&
|
GIT_TRACE2_EVENT="$(pwd)/run-auto.txt" \
|
||||||
test_subcommand git gc --auto <run-auto.txt
|
git maintenance run --auto 2>/dev/null &&
|
||||||
|
GIT_TRACE2_EVENT="$(pwd)/run-no-quiet.txt" \
|
||||||
|
git maintenance run --no-quiet 2>/dev/null &&
|
||||||
|
test_subcommand git gc --quiet <run-no-auto.txt &&
|
||||||
|
test_subcommand git gc --auto --quiet <run-auto.txt &&
|
||||||
|
test_subcommand git gc --no-quiet <run-no-quiet.txt
|
||||||
'
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
Loading…
Reference in New Issue
Block a user