I have an application which spawns a process in order to find occurences of a particular regex within a specific commit in a git repository by running:
git grep -G pattern revision
This works just fine, but the problem is that I do this in a loop and this is extremely slow. I profiled the code on Linux and the call to __libc_fork alone takes 94% of the run-time.
Obviously, I'd like to avoid this unnecessary overhead. To do some other git operations, I'm already using libgit2 in my application, but I don't see a convenient way to perform a regular expression search like I can with git grep. I can imagine manually going through all the files associated with a commit and performing the search, but I was hoping for a more elegant solution, up to a few lines.
Am I missing a relevant libgit2 API? Does anyone know of a quick way to search for a pattern using libgit2?
EDIT Just to clarify: in my loop, the revision is fixed, but the pattern changes.
git log -S pattern, or create a small shell-script that will exit1or0depending if it found whatever you are searching, and then usegit bisectwith that script. - Carlos Campderrósgit grepseems like the right tool for the job. I just need a fasterlibgit2equivalent, but I don't want to write it from scratch. - Dimitar Asenov