checkout: make delayed checkout respect --quiet and --no-progress

The 'Filtering contents...' progress report from delayed checkout is displayed even when checkout and clone are invoked with --quiet or --no-progress. Furthermore, it is displayed unconditionally, without first checking whether stdout is a tty. Let's fix these issues and also add some regression tests for the two code paths that currently use delayed checkout: unpack_trees.c:check_updates() and builtin/checkout.c:checkout_worktree(). Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Matheus Tavares committed Aug 26, 2021 at 16:10 UTC 7a132c628e57b9bceeb88832ea051395c0637b16
5 files changed +80 -5
builtin/checkout.c
+1 -1
@@ -404,7 +404,7 @@ static int checkout_worktree(const struct checkout_opts *opts,
404 mem_pool_discard(&ce_mem_pool, should_validate_cache_entries());
405 remove_marked_cache_entries(&the_index, 1);
406 remove_scheduled_dirs();
407 - errs |= finish_delayed_checkout(&state, &nr_checkouts);
407 + errs |= finish_delayed_checkout(&state, &nr_checkouts, opts->show_progress);
408
409 if (opts->count_checkout_paths) {
410 if (nr_unmerged)
entry.c
+5 -2
@@ -159,7 +159,8 @@ static int remove_available_paths(struct string_list_item *item, void *cb_data)
159 return !available;
160 }
161
162 -int finish_delayed_checkout(struct checkout *state, int *nr_checkouts)
162 +int finish_delayed_checkout(struct checkout *state, int *nr_checkouts,
163 + int show_progress)
164 {
165 int errs = 0;
166 unsigned delayed_object_count;
@@ -173,7 +174,9 @@ int finish_delayed_checkout(struct checkout *state, int *nr_checkouts)
174
175 dco->state = CE_RETRY;
176 delayed_object_count = dco->paths.nr;
176 - progress = start_delayed_progress(_("Filtering content"), delayed_object_count);
177 + progress = show_progress
178 + ? start_delayed_progress(_("Filtering content"), delayed_object_count)
179 + : NULL;
180 while (dco->filters.nr > 0) {
181 for_each_string_list_item(filter, &dco->filters) {
182 struct string_list available_paths = STRING_LIST_INIT_NODUP;
entry.h
+2 -1
@@ -43,7 +43,8 @@ static inline int checkout_entry(struct cache_entry *ce,
43 }
44
45 void enable_delayed_checkout(struct checkout *state);
46 -int finish_delayed_checkout(struct checkout *state, int *nr_checkouts);
46 +int finish_delayed_checkout(struct checkout *state, int *nr_checkouts,
47 + int show_progress);
48
49 /*
50 * Unlink the last component and schedule the leading directories for
t/t0021-conversion.sh
+71
@@ -6,6 +6,7 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8 . ./test-lib.sh
9 +. "$TEST_DIRECTORY"/lib-terminal.sh
10
11 TEST_ROOT="$PWD"
12 PATH=$TEST_ROOT:$PATH
@@ -1061,4 +1062,74 @@ test_expect_success PERL,SYMLINKS,CASE_INSENSITIVE_FS \
1062 )
1063 '
1064
1065 +test_expect_success PERL 'setup for progress tests' '
1066 + git init progress &&
1067 + (
1068 + cd progress &&
1069 + git config filter.delay.process "rot13-filter.pl delay-progress.log clean smudge delay" &&
1070 + git config filter.delay.required true &&
1071 +
1072 + echo "*.a filter=delay" >.gitattributes &&
1073 + touch test-delay10.a &&
1074 + git add . &&
1075 + git commit -m files
1076 + )
1077 +'
1078 +
1079 +test_delayed_checkout_progress () {
1080 + if test "$1" = "!"
1081 + then
1082 + local expect_progress=N &&
1083 + shift
1084 + else
1085 + local expect_progress=
1086 + fi &&
1087 +
1088 + if test $# -lt 1
1089 + then
1090 + BUG "no command given to test_delayed_checkout_progress"
1091 + fi &&
1092 +
1093 + (
1094 + cd progress &&
1095 + GIT_PROGRESS_DELAY=0 &&
1096 + export GIT_PROGRESS_DELAY &&
1097 + rm -f *.a delay-progress.log &&
1098 +
1099 + "$@" 2>err &&
1100 + grep "IN: smudge test-delay10.a .* \\[DELAYED\\]" delay-progress.log &&
1101 + if test "$expect_progress" = N
1102 + then
1103 + ! grep "Filtering content" err
1104 + else
1105 + grep "Filtering content" err
1106 + fi
1107 + )
1108 +}
1109 +
1110 +for mode in pathspec branch
1111 +do
1112 + case "$mode" in
1113 + pathspec) opt='.' ;;
1114 + branch) opt='-f HEAD' ;;
1115 + esac
1116 +
1117 + test_expect_success PERL,TTY "delayed checkout shows progress by default on tty ($mode checkout)" '
1118 + test_delayed_checkout_progress test_terminal git checkout $opt
1119 + '
1120 +
1121 + test_expect_success PERL "delayed checkout ommits progress on non-tty ($mode checkout)" '
1122 + test_delayed_checkout_progress ! git checkout $opt
1123 + '
1124 +
1125 + test_expect_success PERL,TTY "delayed checkout ommits progress with --quiet ($mode checkout)" '
1126 + test_delayed_checkout_progress ! test_terminal git checkout --quiet $opt
1127 + '
1128 +
1129 + test_expect_success PERL,TTY "delayed checkout honors --[no]-progress ($mode checkout)" '
1130 + test_delayed_checkout_progress ! test_terminal git checkout --no-progress $opt &&
1131 + test_delayed_checkout_progress test_terminal git checkout --quiet --progress $opt
1132 + '
1133 +done
1134 +
1135 test_done
unpack-trees.c
+1 -1
@@ -479,7 +479,7 @@ static int check_updates(struct unpack_trees_options *o,
479 errs |= run_parallel_checkout(&state, pc_workers, pc_threshold,
480 progress, &cnt);
481 stop_progress(&progress);
482 - errs |= finish_delayed_checkout(&state, NULL);
482 + errs |= finish_delayed_checkout(&state, NULL, o->verbose_update);
483 git_attr_set_direction(GIT_ATTR_CHECKIN);
484
485 if (o->clone)