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

Optimization for "git clean -ffdx"

From
PMPatrick Marlier <patrick.marlier@gmail.com>
Date
Feb 8, 2022, 22:03 UTC
Message-ID
<CAKQMxzSQRL-Q5daxETF+gYhVScmq_n=r2LJAeEuxpM7=jPajZQ@mail.gmail.com>
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
Next: Elijah Newren
Message 1 of 3 in “Optimization for "git clean -ffdx"”
  1. Patrick MarlierFeb 8, 2022
  2. Elijah NewrenFeb 13, 2022
  3. Patrick MarlierFeb 15, 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.