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

Re: BUG: git grep behave oddly with alternatives

From
Jeff King <peff@peff.net>
Date
Jan 12, 2023, 21:54 UTC
Message-ID
<Y8CBrtmL45tA/N8z@coredump.intra.peff.net>
In-Reply-To
<4165031d-e7f1-0477-2245-6a8e312de522@web.de>
On Thu, Jan 12, 2023 at 06:13:13PM +0100, René Scharfe wrote:
Show 16 quoted lines
> > I'm not quite sure what you mean here by "non-greedy repetitions".
> > Something like:
> >
> >   # prefer "foo bar" to "foo bar bar"; only matters for colorizing or
> >   # --only-matching
> >   git grep -E 'foo.*?bar'
> >
> > ? If so, then yeah, that changes the meaning of a bare "?" and people
> > might be surprised by it.
> 
> Right.  To be fair, question mark is a special character and you'd
> probably need to quote it anyway if you want to match a literal
> question mark.  Otherwise I get:
> 
>    $ git grep -E 'foo.*?bar'
>    fatal: command line, 'foo.*?bar': repetition-operator operand invalid
This is on macOS, I assume? With glibc it seems to be quietly ignored:
  $ git grep -E -o 'foo.*?ba' .clang-format
  .clang-format:foo, bar, ba

So it is not treated literally (as it would be without -E). But nor does it make the match non-greedy (otherwise it would have output "foo, ba", as "git grep -P" does).

So it does seem like all bets are off for what people can and should expect here. Which isn't to say we should make things worse. I mostly wondered if REG_ENHANCED might take us closer to what glibc was doing by default, but it doesn't seem like it.

-Peff
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 14 of 22 in “BUG: git grep behave oddly with alternatives”
  1. Marco NenciariniJan 3, 2023
  2. René ScharfeJan 3, 2023
  3. Marco NenciariniJan 3, 2023
  4. René ScharfeJan 3, 2023
  5. Junio C HamanoJan 4, 2023
  6. Jeff KingJan 4, 2023
  7. René ScharfeJan 4, 2023
  8. Jeff KingJan 6, 2023
  9. René ScharfeJan 8, 2023
  10. Junio C HamanoJan 8, 2023
  11. Jeff KingJan 11, 2023
  12. René ScharfeJan 12, 2023
  13. Ævar Arnfjörð BjarmasonJan 12, 2023
  14. Jeff KingJan 12, 2023
  15. Ævar Arnfjörð BjarmasonJan 13, 2023
  16. Junio C HamanoJan 13, 2023
  17. René ScharfeJan 14, 2023
  18. René ScharfeJan 14, 2023
  19. Diomidis SpinellisJan 14, 2023
  20. Junio C HamanoJan 14, 2023
  21. René ScharfeJan 13, 2023
  22. René ScharfeJan 13, 2023

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.