]> git.ipfire.org Git - thirdparty/git.git/commitdiff
checkout: make delayed checkout respect --quiet and --no-progress
authorMatheus Tavares <matheus.bernardino@usp.br>
Thu, 26 Aug 2021 19:10:06 +0000 (16:10 -0300)
committerJunio C Hamano <gitster@pobox.com>
Fri, 27 Aug 2021 06:15:33 +0000 (23:15 -0700)
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>
builtin/checkout.c
entry.c
entry.h
t/t0021-conversion.sh
unpack-trees.c

index b5d477919a743885ab536608e86d28662ac3b615..b23bc149d17b83686709c843e540f834e54620bc 100644 (file)
@@ -404,7 +404,7 @@ static int checkout_worktree(const struct checkout_opts *opts,
        mem_pool_discard(&ce_mem_pool, should_validate_cache_entries());
        remove_marked_cache_entries(&the_index, 1);
        remove_scheduled_dirs();
-       errs |= finish_delayed_checkout(&state, &nr_checkouts);
+       errs |= finish_delayed_checkout(&state, &nr_checkouts, opts->show_progress);
 
        if (opts->count_checkout_paths) {
                if (nr_unmerged)
diff --git a/entry.c b/entry.c
index 125fabdbd52c4d042e40ad66ef9c12fff846e25a..044e8ec92c6c3188028a31d4f5e497ab46178272 100644 (file)
--- a/entry.c
+++ b/entry.c
@@ -159,7 +159,8 @@ static int remove_available_paths(struct string_list_item *item, void *cb_data)
        return !available;
 }
 
-int finish_delayed_checkout(struct checkout *state, int *nr_checkouts)
+int finish_delayed_checkout(struct checkout *state, int *nr_checkouts,
+                           int show_progress)
 {
        int errs = 0;
        unsigned delayed_object_count;
@@ -173,7 +174,9 @@ int finish_delayed_checkout(struct checkout *state, int *nr_checkouts)
 
        dco->state = CE_RETRY;
        delayed_object_count = dco->paths.nr;
-       progress = start_delayed_progress(_("Filtering content"), delayed_object_count);
+       progress = show_progress
+               ? start_delayed_progress(_("Filtering content"), delayed_object_count)
+               : NULL;
        while (dco->filters.nr > 0) {
                for_each_string_list_item(filter, &dco->filters) {
                        struct string_list available_paths = STRING_LIST_INIT_NODUP;
diff --git a/entry.h b/entry.h
index b8c0e170dc791a7bebde1e6e71c194f3301a9cff..7c889e58fd7831086afe9b9267f537bcd9a80dca 100644 (file)
--- a/entry.h
+++ b/entry.h
@@ -43,7 +43,8 @@ static inline int checkout_entry(struct cache_entry *ce,
 }
 
 void enable_delayed_checkout(struct checkout *state);
-int finish_delayed_checkout(struct checkout *state, int *nr_checkouts);
+int finish_delayed_checkout(struct checkout *state, int *nr_checkouts,
+                           int show_progress);
 
 /*
  * Unlink the last component and schedule the leading directories for
index b5749f327dd17bd4577fc3764e811020117cd9ef..33dfc9cd562327b725a3338ac0e9b6787f58c9fe 100755 (executable)
@@ -6,6 +6,7 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
 
 . ./test-lib.sh
+. "$TEST_DIRECTORY"/lib-terminal.sh
 
 TEST_ROOT="$PWD"
 PATH=$TEST_ROOT:$PATH
@@ -1061,4 +1062,74 @@ test_expect_success PERL,SYMLINKS,CASE_INSENSITIVE_FS \
        )
 '
 
+test_expect_success PERL 'setup for progress tests' '
+       git init progress &&
+       (
+               cd progress &&
+               git config filter.delay.process "rot13-filter.pl delay-progress.log clean smudge delay" &&
+               git config filter.delay.required true &&
+
+               echo "*.a filter=delay" >.gitattributes &&
+               touch test-delay10.a &&
+               git add . &&
+               git commit -m files
+       )
+'
+
+test_delayed_checkout_progress () {
+       if test "$1" = "!"
+       then
+               local expect_progress=N &&
+               shift
+       else
+               local expect_progress=
+       fi &&
+
+       if test $# -lt 1
+       then
+               BUG "no command given to test_delayed_checkout_progress"
+       fi &&
+
+       (
+               cd progress &&
+               GIT_PROGRESS_DELAY=0 &&
+               export GIT_PROGRESS_DELAY &&
+               rm -f *.a delay-progress.log &&
+
+               "$@" 2>err &&
+               grep "IN: smudge test-delay10.a .* \\[DELAYED\\]" delay-progress.log &&
+               if test "$expect_progress" = N
+               then
+                       ! grep "Filtering content" err
+               else
+                       grep "Filtering content" err
+               fi
+       )
+}
+
+for mode in pathspec branch
+do
+       case "$mode" in
+       pathspec) opt='.' ;;
+       branch) opt='-f HEAD' ;;
+       esac
+
+       test_expect_success PERL,TTY "delayed checkout shows progress by default on tty ($mode checkout)" '
+               test_delayed_checkout_progress test_terminal git checkout $opt
+       '
+
+       test_expect_success PERL "delayed checkout ommits progress on non-tty ($mode checkout)" '
+               test_delayed_checkout_progress ! git checkout $opt
+       '
+
+       test_expect_success PERL,TTY "delayed checkout ommits progress with --quiet ($mode checkout)" '
+               test_delayed_checkout_progress ! test_terminal git checkout --quiet $opt
+       '
+
+       test_expect_success PERL,TTY "delayed checkout honors --[no]-progress ($mode checkout)" '
+               test_delayed_checkout_progress ! test_terminal git checkout --no-progress $opt &&
+               test_delayed_checkout_progress test_terminal git checkout --quiet --progress $opt
+       '
+done
+
 test_done
index 5786645f315d51be62badb5faa8cb5b8d26f70d2..f07304f1b714cfb5cbd4eb8c9b2bc5255807514e 100644 (file)
@@ -479,7 +479,7 @@ static int check_updates(struct unpack_trees_options *o,
                errs |= run_parallel_checkout(&state, pc_workers, pc_threshold,
                                              progress, &cnt);
        stop_progress(&progress);
-       errs |= finish_delayed_checkout(&state, NULL);
+       errs |= finish_delayed_checkout(&state, NULL, o->verbose_update);
        git_attr_set_direction(GIT_ATTR_CHECKIN);
 
        if (o->clone)