Skip to content

Commit 7a132c6

Browse files
matheustavaresgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 225bc32 commit 7a132c6

File tree

5 files changed

+80
-5
lines changed

5 files changed

+80
-5
lines changed

builtin/checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ static int checkout_worktree(const struct checkout_opts *opts,
404404
mem_pool_discard(&ce_mem_pool, should_validate_cache_entries());
405405
remove_marked_cache_entries(&the_index, 1);
406406
remove_scheduled_dirs();
407-
errs |= finish_delayed_checkout(&state, &nr_checkouts);
407+
errs |= finish_delayed_checkout(&state, &nr_checkouts, opts->show_progress);
408408

409409
if (opts->count_checkout_paths) {
410410
if (nr_unmerged)

entry.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ static int remove_available_paths(struct string_list_item *item, void *cb_data)
159159
return !available;
160160
}
161161

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)
163164
{
164165
int errs = 0;
165166
unsigned delayed_object_count;
@@ -173,7 +174,9 @@ int finish_delayed_checkout(struct checkout *state, int *nr_checkouts)
173174

174175
dco->state = CE_RETRY;
175176
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;
177180
while (dco->filters.nr > 0) {
178181
for_each_string_list_item(filter, &dco->filters) {
179182
struct string_list available_paths = STRING_LIST_INIT_NODUP;

entry.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ static inline int checkout_entry(struct cache_entry *ce,
4343
}
4444

4545
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);
4748

4849
/*
4950
* Unlink the last component and schedule the leading directories for

t/t0021-conversion.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
66
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
77

88
. ./test-lib.sh
9+
. "$TEST_DIRECTORY"/lib-terminal.sh
910

1011
TEST_ROOT="$PWD"
1112
PATH=$TEST_ROOT:$PATH
@@ -1061,4 +1062,74 @@ test_expect_success PERL,SYMLINKS,CASE_INSENSITIVE_FS \
10611062
)
10621063
'
10631064

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+
10641135
test_done

unpack-trees.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ static int check_updates(struct unpack_trees_options *o,
479479
errs |= run_parallel_checkout(&state, pc_workers, pc_threshold,
480480
progress, &cnt);
481481
stop_progress(&progress);
482-
errs |= finish_delayed_checkout(&state, NULL);
482+
errs |= finish_delayed_checkout(&state, NULL, o->verbose_update);
483483
git_attr_set_direction(GIT_ATTR_CHECKIN);
484484

485485
if (o->clone)

0 commit comments

Comments
 (0)