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

Re: [PATCH] built-in "git grep" (git grip).

From
Junio C Hamano <junkio@cox.net>
Date
May 2, 2006, 19:07 UTC
Message-ID
<7v1wvcmejr.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<e378fs$lpc$1@sea.gmane.org>
Jakub Narebski <jnareb@gmail.com> writes:
Show 5 quoted lines
>> I renamed "git grip" to "git grep" and "git diffn" to "git diff"
>> both in "next" branch to avoid confusion.  Thanks Andreas,
>> Jakub, and others for input.
>
> So, is there a way to use old, script version of those commands?

I'd say that is probably not the real question you wanted to ask, but let's pretend it is for a moment.

The "master" branch has not been updated to remove the script one, so you can keep running "master" one (or 1.3.X series). Or you can fork your own private edition by tweaking git.c (prevent it from running the builtin one) and Makefile (resurrect the script based one and prevent it from installing git-grep hardlinked with git itself). One thing that I will not do in the long run, however, is to keep the script based one and have builtin one. It is like carrying all the earlier slightly incompatible versions as git-grep-1.1.sh, git-grep-1.2.sh, and git-grep-1.3.sh in the source for fear of backward compatibility problems -- it is crazy.

So the real question, is what are still missing in the built-in implementation. What will we lose if we remove the script based one and replace it with today's built-in one, if we are ready to do it today, and if not what we are going to do about them. My answer to the latter questions are "not yet" (obviously, that is why "master" does not have it yet), and "will support what are reasonable".

Here are main differences that I am aware of:
 - The shell-script one, if you use GNU grep, accepts more
   options to grep than what the current built-in one supports.
   Notable ones that are missing: fixed strings (-F), patterns
   from file (-f), count matches (-c), omit filenames (-h),
   skipping binary files (-I, -U), files without match (-L),
   pcre (-P), silent (-q), word expression (-w), NUL (-z).  They
   should be easy to add if somebody cares enough, and I plan to
   do a few myself before pushing it out to "master".
 - The shell-script one can be coaxed to use different "grep"
   implementation from the standard one with an appropriate PATH
   settings.

At the lowest level, buitlin-grep.c::grep_buffer() function is called with the set of parsed options, the "filename" used for reporting, and the text to grepped in-core. The shell-script one always worked on working tree files, but the built-in one can work on working tree files and also alternatively on files from other versions. Regardless of where the file comes from, this function is called to look for the pattern the user is looking for.

You can do two things.

One is to add support for commonly used but still missing features to built-in one. For this, you would need to extend "struct grep_opt" to hold new option parameters (e.g. if you want to do "-f", you would need to hold all patterns you obtain from the named file so grep_buffer() can use them -- currently it supports only one pattern), and teach grep_buffer() how to do the new feature.

Another thing you can do is to detect GIT_EXTERNAL_GREP (in the same spirit as GIT_EXTERNAL_DIFF) environment variable at the front of grep_buffer(), and when it is set, spawn the named external program with the original parameters the user supplied, probably stashed away in "struct grep_opt" when cmd_grep() does its parameter parsing, and feed it the contents of the buffer.

Previous: Andreas EricssonNext: Linus Torvalds
Message 10 of 21 in “built-in "git grep" (git grip).”
  1. built-in "git grep" (git grip).Junio C Hamano, May 1, 2006
  2. Jakub NarebskiMay 1, 2006
  3. Junio C HamanoMay 1, 2006
  4. Jakub NarebskiMay 1, 2006
  5. Andreas EricssonMay 2, 2006
  6. Jakub NarebskiMay 2, 2006
  7. Junio C HamanoMay 2, 2006
  8. Jakub NarebskiMay 2, 2006
  9. Andreas EricssonMay 2, 2006
  10. Junio C HamanoMay 2, 2006
  11. Linus TorvaldsMay 2, 2006
  12. Junio C HamanoMay 2, 2006
  13. Linus TorvaldsMay 2, 2006
  14. Junio C HamanoMay 3, 2006
  15. built-in "git grep" (git grip) - quickfixJunio C Hamano, May 1, 2006
  16. Sam RavnborgMay 1, 2006
  17. Sam RavnborgMay 1, 2006
  18. Sam RavnborgMay 1, 2006
  19. Linus TorvaldsMay 1, 2006
  20. builtin-grep: wildcard pathspec fixesJunio C Hamano, May 1, 2006
  21. builtin-grep: do not use setup_revisions()Junio C Hamano, May 1, 2006

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.