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

Re: BUG: git grep behave oddly with alternatives

From
René Scharfe <l.s.r@web.de>
Date
Jan 12, 2023, 17:13 UTC
Message-ID
<4165031d-e7f1-0477-2245-6a8e312de522@web.de>
In-Reply-To
<Y78GXZvyrOrXhe7n@coredump.intra.peff.net>
Am 11.01.23 um 19:56 schrieb Jeff King:
Show 16 quoted lines
> On Sun, Jan 08, 2023 at 01:42:04AM +0100, René Scharfe wrote:
>
>> REG_ENHANCED on macOS affects REG_EXTENDED as well.  It unlocks e.g.
>> non-greedy repetitions and inline comments.  Sounds nice, but also
>> potentially surprising.  I was unable to find a current version of
>> the re_format(7) manpage online, unfortunately.
>
> 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
Show 13 quoted lines
>> Apple's latest version of Git sets NO_REGEX and thus uses
>> compat/regex, if I read their source correctly:
>>
>> https://github.com/apple-oss-distributions/Git/blob/Git-128/src/git/Makefile#L1302
>>
>> The easiest and most consistent option would be to do the same.  But
>> we can't do that, because it would break multibyte support, which was
>> fixed by 1819ad327b (grep: fix multibyte regex handling under macOS,
>> 2022-08-26), which started to use the system regex functions again.
>
> Looks like that NO_REGEX line was dropped by 1819ad327b. So I don't
> think Apple added it themselves; their version is just based on an older
> version of Git (looks like 2.24.3).
Makes sense.
Show 8 quoted lines
>> Which begs the question: Isn't that a problem for the platforms that
>> still have to use NO_REGEX?  Shouldn't we fix compat/regex?
>
> I'm not sure. I always assumed our fallback was similar-ish to what was
> in glibc and was thus pretty featureful, but that may not be true (it
> actually comes from gawk). It looks like we just didn't pull over the
> multi-byte parts in a997bf423d (compat/regex: get the gawk regex engine
> to compile within git, 2010-08-17).

GAWK removed NO_MBSUPPORT, NO_MBSUPPORT and mbsupport.h in the meantime. I guess that means they support multi-byte characters everywhere now.

René
Previous: Jeff KingNext: Ævar Arnfjörð Bjarmason
Message 12 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.