Search code examples
gitgrepxargsgit-grep

git-grep not using multiple threads


I am trying to use git grep to search all revisions of a very large repository. The command I am using is:

$ git rev-list --all | xargs git grep -I --threads 10 --line-number \
  --only-matching "SomeString"

I am using the latest official version of git on mac:

$ git --version
git version 2.19.1

It's taking a very long time, looking at activity monitor git is only using one thread. However the docs say it should use 8 by default. It only uses one thread with or without the --threads <num> option. I don't have any other config set that would override this setting either:

$ git config --list
credential.helper=osxkeychain
user.name=****
user.email=****

Any ideas what I'm missing? Can anybody else use git-grep and confirm that they see multiple threads?

Thanks for any help


Solution

  • I wonder if it's because you're using | xargs, which waits for input on stdin. Since the output from git rev-list is a single stream, xargs, by default will use only one process:

    -P max-procs, --max-procs=max-procs
                  Run up to max-procs processes at a time; **the default is 1**.  If
                  max-procs is 0, xargs will run as many processes as possible
                  at a time.
    

    So try increasing it using the above flag:

    git rev-list --all | xargs -P 10 git grep -I --threads 1 --line-number \
        --only-matching "SomeString"
    

    This will spawn multiple git greps, rather that enable git grep to use multiple threads, so a sort-of-functional answer.