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
MLMatthias Lederhofer <matled@gmx.net>
Date
Jun 30, 2006, 07:46 UTC
Message-ID
<E1FwDiI-0007Xp-2s@moooo.ath.cx>
In-Reply-To
<7v7j2zmgbu.fsf@assigned-by-dhcp.cox.net>
(Junio: please reply to this one, forgot the Cc in the first one :/)
Junio C Hamano wrote:
Show 21 quoted lines
> Matthias Lederhofer <matled@gmx.net> writes:
> 
> > OR and AND have precedence, so there are two possibilities, I'd take
> > the first one.
> > 1. OR, AND:
> >     This will make it easier to read because OR can be skipped:
> >       pat1 pat2 AND pat3 pat4
> >     = pat1 OR pat2 AND pat3 OR pat4
> >     = (pat1 OR pat2) AND (pat3 OR pat4)
> > 2. AND, OR:
> >     This is a bit more logic if you think of AND as * and OR as +.
> 
> > ... FOO should not be named --and imo but I don't have any idea
> > for a good name atm.
> 
> I personally feel FOO should not even exist.  An option that
> covers the entire expression to make operator precedence in it
> sounds quite evil.  
> 
> I would say make --and bind tighter than --or and use parentheses as
> needed.

Ok, perhaps changing operator precedence is a bit much. What do you think of that then: Operator precedence AND, OR. The FOO options changes the default operator to AND. This also seems quite natural if you think of AND as * and OR as +: A B + C D = A * B + C * D = (A * B) + (C * D)

A few examples to get an impression how the command line could look like: A OR B OR (C AND D) => A B C AND D (A OR B OR C) AND D => (A B C) AND D A AND B AND (C OR D) => -FOO A B (C OR D) (A AND B AND C) OR D => -FOO A B C OR D

Perhaps we even could use options which are similar to * and +, for
example:
 - -* and -+ (-* should not be expanded often but is annoying anyway)
 - -. and -+
 - -t and -p (A -t B is A times B, A -p B is A plus B)
> Making --or optional sounds fine as that
> would make the default "multiple -e" case similar to what GNU
> grep does without any --and nor --or.

That's exactly what I was thinking about: make extended expressions compatible to current grep options. This will confuse less people and there is no need for an extra option to activate this.

Previous: Junio C HamanoNext: Junio C Hamano
Message 13 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.