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

Re: [PATCH] git-grep: --and to combine patterns with and instead of or

From
Junio C Hamano <junkio@cox.net>
Date
Jun 30, 2006, 18:16 UTC
Message-ID
<7v1wt6ik4x.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<e83p0q$dla$1@sea.gmane.org>
Jakub Narebski <jnareb@gmail.com> writes:
Show 6 quoted lines
> Because --near needs an expression it check context for (context is for
> found match of lhs expression). So
>
>   -e foo --near \( -e A --or -e B \)
>
> means lines containing foo and either A or B in the context _for "foo"_.

The syntax and semantics of --near I suggested (and you are following) and what Matthias discusses are different and I think that is why you two are talking past each other.

What I originally suggested is that you can (syntactically) replace --near with --and. That is, the LHS is the match and RHS is "the LHS must match, but in addition RHS must match but unlike --and RHS does not have to be exactly on the same line but it is OK if it is a line somewhere nearby".

The --near Matthias talk about is syntactically not like --and but more like --not. It takes a condition for a line after that, and loosens it to cover nearby lines. So "-e A" means "the line must have A on it" but "--near -e A" means "the line must be nearby a line that satisfies `-e A'".

Matthias's "--near EXP" is spelled as "-e '' --near EXP" (the first one is always true) with our syntax, in other words.

I do not think either of these semantics is invalid; they are just different. The version by Matthias is more general and more expressive.

Previous: Jakub NarebskiNext: Jakub Narebski
Message 28 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.