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

Re: [PATCH] git-grep: boolean expression on pattern matching.

From
MLMatthias Lederhofer <matled@gmx.net>
Date
Jun 30, 2006, 15:11 UTC
Message-ID
<E1FwKeN-000087-5x@moooo.ath.cx>
In-Reply-To
<7vsllnj6rh.fsf_-_@assigned-by-dhcp.cox.net>
Show 10 quoted lines
> This extends the behaviour of git-grep when multiple -e options
> are given.  So far, we allowed multiple -e to behave just like
> regular grep with multiple -e, i.e. the patterns are OR'ed
> together.
> 
> With this change, you can also have multiple patterns AND'ed
> together, or form boolean expressions, like this (the
> parentheses are quoted from the shell in this example):
> 
> 	$ git grep -e _PATTERN --and \( -e atom -e token \)
This looks really nice. So for a few trivial tests it did not fail :)

I noticed an unrelated bug. The context separators ("--") are missing between matches in different files:

$ git-grep -e foobar -A 1 (this uses external grep) Documentation/git-diff-tree.txt:I.e. "foo" does not pick up `foobar.h`. "foo" does match `foo/bar.h` Documentation/git-diff-tree.txt-so it can be used to name subdirectories. -- git-send-email.perl:#$initial_reply_to = ''; #<20050203173208.GA23964@foobar.com>'; git-send-email.perl- -- [..]

$ git-grep -e foobar -A 1 master (this is internal grep) master:Documentation/git-diff-tree.txt:I.e. "foo" does not pick up `foobar.h`. "foo" does match `foo/bar.h` master:Documentation/git-diff-tree.txt-so it can be used to name subdirectories. master:git-send-email.perl:#$initial_reply_to = ''; #<20050203173208.GA23964@foobar.com>'; master:git-send-email.perl- [..]

I think this cannot be fixed in the loop in builtin-grep.c:grep_cache because after the last hit there should be no separator but it is not known if a grep_sha1/grep_file will match and produce output. So I think there has to be a variable passed down which tells those functions to print the separator before any other output.

Previous: Junio C HamanoNext: Matthias Lederhofer
Message 18 of 32 in “git-grep: allow patterns starting with -”
  1. git-grep: allow patterns starting with -Matthias Lederhofer, Jun 25, 2006
  2. Timo HirvonenJun 25, 2006
  3. correct documentation for git grepMatthias Lederhofer, Jun 25, 2006
  4. Johannes SchindelinJun 25, 2006
  5. correct documentation for git grepMatthias Lederhofer, Jun 25, 2006
  6. correct documentation for git grepMatthias Lederhofer, Jun 26, 2006
  7. Johannes SchindelinJun 26, 2006
  8. git-grep: --and to combine patterns with and instead of orMatthias Lederhofer, Jun 26, 2006
  9. Thomas GlanzmannJun 29, 2006
  10. Junio C HamanoJun 29, 2006
  11. Matthias LederhoferJun 30, 2006
  12. Junio C HamanoJun 30, 2006
  13. Matthias LederhoferJun 30, 2006
  14. Junio C HamanoJun 30, 2006
  15. git-grep: boolean expression on pattern matching.Junio C Hamano, Jun 30, 2006
  16. Jakub NarebskiJun 30, 2006
  17. Junio C HamanoJun 30, 2006
  18. Matthias LederhoferJun 30, 2006
  19. Matthias LederhoferJun 30, 2006
  20. Junio C HamanoJun 30, 2006
  21. Matthias LederhoferJun 30, 2006
  22. Junio C HamanoJun 30, 2006
  23. Jakub NarebskiJun 30, 2006
  24. Matthias LederhoferJun 30, 2006
  25. Junio C HamanoJun 30, 2006
  26. Matthias LederhoferJun 30, 2006
  27. Jakub NarebskiJun 30, 2006
  28. Junio C HamanoJun 30, 2006
  29. Jakub NarebskiJun 30, 2006
  30. Junio C HamanoJun 30, 2006
  31. Andreas EricssonJul 3, 2006
  32. Matthias LederhoferJun 25, 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.