git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Patrick Marlier <patrick.marlier@gmail.com>
To: git@vger.kernel.org
Subject: Optimization for "git clean -ffdx"
Date: Tue, 8 Feb 2022 23:03:49 +0100	[thread overview]
Message-ID: <CAKQMxzSQRL-Q5daxETF+gYhVScmq_n=r2LJAeEuxpM7=jPajZQ@mail.gmail.com> (raw)

Dear git Developers,

In a big repository with a lot of untracked directories and files
(build in tree), "git clean -ffdx" can be optimized. Indeed, "git
clean" goes recursively into all untracked and nested directories to
look for .git files even if "-ff" is specified.
Using breakpoint on stat or "strace -e newfstatat", it is possible to
see the recursing search for ".git" and ".git/HEAD". Also it seems to
traverse the untracked directories a few times, which I am not sure
why.

Using "-ff" should not check for nested .git and no need to recurse if
the directory is already untracked.

Doing the following, it seems to avoid looking for nested .git and all
tests are passing.

@@ -1007,6 +1008,12 @@ int cmd_clean(int argc, const char **argv,
const char *prefix)
                 * the code clearer to exclude it, though.
                 */
                dir.flags |= DIR_KEEP_UNTRACKED_CONTENTS;
+
+               /*
+                * No need to go to deeper in directories if already untracked
+                */
+               if (rm_flags == 0)
+                       dir.flags |= DIR_NO_GITLINKS;
        }

        if (read_cache() < 0)

However reading the documentation of DIR_NO_GITLINKS seems to say that
is not the right fix.

Another thing to note is that it shows "Removing XXX" but it shows it
when the directory is already gone. So we could change to "Removed
XXX" or display the "Removing XXX" before starting to remove the
directory.

Thanks in advance for any fix or help in getting it right.
--
Patrick Marlier

             reply	other threads:[~2022-02-08 22:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-08 22:03 Patrick Marlier [this message]
2022-02-13  3:25 ` Optimization for "git clean -ffdx" Elijah Newren
2022-02-15 22:16   ` Patrick Marlier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAKQMxzSQRL-Q5daxETF+gYhVScmq_n=r2LJAeEuxpM7=jPajZQ@mail.gmail.com' \
    --to=patrick.marlier@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).