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, 17:18 UTC
Message-ID
<7vpsgqimu7.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<E1FwMPf-0005XA-N9@moooo.ath.cx>
Matthias Lederhofer <matled@gmx.net> writes:
> 1. Should the context of near be the same as -[ABC] or perhaps
>    --near=N / --near=N:M (default could be the same as specified by
>    -[ABC]).
As an end-user, I do not care either way.
> 2. Should it be possible to specify another boolean expression after
>    --near? e.g. --near ( -e foo --or ( -e bar --and -e baz )) to match
>    if the context contains foo or 'bar and baz'.
I would say why not.
> 3. Is --near just another subexpression? e.g. search for foo with
>    either A or B in the context:
>    -e foo --and ( --near A --or --near B )
>    This does not make sense without 1 and 2.

Ah, interesting. I was thinking --near to be weaker form of --and, but you made it to be a unary predicate (like --not). That would be neater.

Show 6 quoted lines
> With some or all of those features quite mighty and complex
> expressions can be build:
> -e A --and --near=3:-1 ( -e B --and --near=0:0 ( -e foo --and -e bar ) )
> This could mean: find lines containing A and have B in any of the 3
> lines before A (without the line containing A). Additionally foo and
> bar have to be found on the same line before A.

Having said that, I suspect the above made-up example may not be so useful in practice. I think a more realistic usage is "I want to find lines that contain `made-up' and `realistic' but the paragraph might have been filled by the editor and they may be found on separate nearby lines. Instead of saying `-e made-up --and -e realistic', I would say `-e made-up --near -e realistic' to find what I want". That would find the first two lines of this paragraph, among others.

> With the new extended expressions it would be really nice if git-grep
> could also be used outside a git repository :)

I am not sure about `outside' but it might be useful to extend the working tree walker and glob filter used there to match what ls-files uses so that it can do untracked files as well.

Previous: Matthias LederhoferNext: Jakub Narebski
Message 22 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.