Subject: Re: git bug: Perl compatible regular expressions do not work as expected

From: Junio C Hamano <[email-masked]>
Date: Mon, 27 Mar 2023 09:29:14 -0700

René Scharfe <[email-masked]> writes:

> Am 25.03.23 um 14:09 schrieb Mario Grgic:
>> The lowercase -p is to print the output in patch format. You can rewrite the command line as
>>
>>  git log --all --patch --perl-regexp -G '\bmain\b’
>>
>> I still get no output in any git version after 2.38.4
>
> -G doesn't support Perl regular expressions.  --perl-regexp only affects
> --grep, --grep-reflog, --author, and --committer.  Neither POSIX basic
> nor extended regular expressions support \b as word boundary.  GNU regex
> and our compat/regex/ do, as extensions.  macOS regex supports it if the
> flag REG_ENHANCED is given to regcomp(3).

Good summary to unconfuse speculations in the thread.

> So perhaps this is rather a feature request to support Perl regular
> expressions for -G (and probably -S as well).  

Perhaps.  I used to be a "it would be wonderful if pcre were usable
everywhere" dreamer, but after seeing our share of bugs caused by
use of pcre, I am not a huge proponent anymore.  I do not object to
such an enhancement at all, as long as it is done cleanly and in
such a way that it is clear pcre cannot be used by accident when the
user does not ask for it.

> Or to enable REG_ENHANCED
> for them, at least, like 54463d32ef (use enhanced basic regular
> expressions on macOS, 2023-01-08) did to get alternations for git grep
> on macOS.

This one sounds like a reasonable thing, which may not have huge
unintended fallout, to do.  I am a bit surprised that we have to
cover each individual callsite of regcomp(3), though.  Doesn't the
54463d32ef fix use "#define regcomp git_regcomp" to cover everybody?