git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] clean: avoid to differentiate untracked and ignored when appropriate

From
Elijah Newren <newren@gmail.com>
Date
Feb 16, 2022, 04:16 UTC
Message-ID
<CABPp-BFnrd4=DM-xQtw+j=LRkA4fwYp1EZ2j3cBVjZRsYPU-9Q@mail.gmail.com>
In-Reply-To
<20220215221615.20683-2-patrick.marlier@gmail.com>

On Tue, Feb 15, 2022 at 2:16 PM Patrick Marlier <patrick.marlier@gmail.com> wrote:

Could I suggest a bit longer commit message?  Perhaps:

""" clean: avoid traversing into untracked dirs when unnecessary

When deleting all untracked and ignored files and any nested repositories (such as with `git clean -ffdx`), we do not need to recurse into an untracked directory to see if any of the entries under it are ignored or a nested repository. Special case this condition to avoid unnecessary recursion. """

Show 31 quoted lines
> ---
>  builtin/clean.c  |  4 +++-
>  t/t7300-clean.sh | 24 ++++++++++++++++++++++++
>  2 files changed, 27 insertions(+), 1 deletion(-)
>
> diff --git a/builtin/clean.c b/builtin/clean.c
> index 18b37e3fd9..1b1454d052 100644
> --- a/builtin/clean.c
> +++ b/builtin/clean.c
> @@ -978,7 +978,9 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
>                 remove_directories = 1;
>         }
>
> -       if (remove_directories && !ignored_only) {
> +       if (remove_directories && ignored && !exclude_list.nr && force > 1)
> +               ; /* No need to recurse to look for ignored files */
> +       else if (remove_directories && !ignored_only) {
>                 /*
>                  * We need to know about ignored files too:
>                  *
> diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh
> index 0399701e62..684eba914b 100755
> --- a/t/t7300-clean.sh
> +++ b/t/t7300-clean.sh
> @@ -788,4 +788,28 @@ test_expect_success 'traverse into directories that may have ignored entries' '
>         )
>  '
>
> +test_expect_success 'avoid traversing into untracked directories' '
> +       test_when_finished rm -f output error trace.* &&
> +       test_create_repo avoid-traversing-untracked-hierarchy &&

I think you may have been copying from an example earlier in the file that I like wrote. As someone else recently pointed out to me, t/test-lib-functions.sh points out that test_create_repo is deprecated and we should just use "git init <dirname>" instead.

Show 24 quoted lines
> +       (
> +               cd avoid-traversing-untracked-hierarchy &&
> +
> +               mkdir -p untracked/subdir/with/b &&
> +               mkdir -p untracked/subdir/with/a &&
> +               >untracked/subdir/with/a/random-file.txt &&
> +
> +               GIT_TRACE2_PERF="$TRASH_DIRECTORY/trace.output" \
> +               git clean -ffdx
> +       ) &&
> +
> +       # Make sure we only visited into the top-level directory, and did
> +       # not traverse into the "untracked" subdirectory since it was excluded
> +       grep data.*read_directo.*directories-visited trace.output |
> +               cut -d "|" -f 9 >trace.relevant &&
> +       cat >trace.expect <<-EOF &&
> +        ..directories-visited:1
> +       EOF
> +       test_cmp trace.expect trace.relevant
> +'
> +
>  test_done
> --
> 2.35.1
Looks good, other than those minor items.  Thanks for working on this!
Previous: Patrick MarlierNext: Elijah Newren
Message 3 of 4 in “clean: avoid looking for nested repository when appropriate”
  1. 1/2 clean: avoid looking for nested repository when appropriatePatrick Marlier, Feb 15, 2022
  2. 2/2 clean: avoid to differentiate untracked and ignored when appropriatePatrick Marlier, Feb 15, 2022
  3. Elijah NewrenFeb 16, 2022
  4. Elijah NewrenFeb 16, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.