use enhanced basic regular expressions on macOS

When 1819ad327b (grep: fix multibyte regex handling under macOS, 2022-08-26) started to use the native regex library instead of Git's own (compat/regex/), it lost support for alternation in basic regular expressions. Bring it back by enabling the flag REG_ENHANCED on macOS when compiling basic regular expressions. Reported-by: Marco Nenciarini <marco.nenciarini@enterprisedb.com> Suggested-by: Jeff King <peff@peff.net> Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Jan 8, 2023 at 01:42 UTC 54463d32ef6798c772c8bbf69b2c1897a854db9f
4 files changed +24
Makefile
+9
@@ -289,6 +289,10 @@ include shared.mak
289 # Define NO_REGEX if your C library lacks regex support with REG_STARTEND
290 # feature.
291 #
292 +# Define USE_ENHANCED_BASIC_REGULAR_EXPRESSIONS if your C library provides
293 +# the flag REG_ENHANCED and you'd like to use it to enable enhanced basic
294 +# regular expressions.
295 +#
296 # Define HAVE_DEV_TTY if your system can open /dev/tty to interact with the
297 # user.
298 #
@@ -2040,6 +2044,11 @@ endif
2044 ifdef NO_REGEX
2045 COMPAT_CFLAGS += -Icompat/regex
2046 COMPAT_OBJS += compat/regex/regex.o
2047 +else
2048 +ifdef USE_ENHANCED_BASIC_REGULAR_EXPRESSIONS
2049 + COMPAT_CFLAGS += -DUSE_ENHANCED_BASIC_REGULAR_EXPRESSIONS
2050 + COMPAT_OBJS += compat/regcomp_enhanced.o
2051 +endif
2052 endif
2053 ifdef NATIVE_CRLF
2054 BASIC_CFLAGS += -DNATIVE_CRLF
compat/regcomp_enhanced.c new
+9
@@ -0,0 +1,9 @@
1 +#include "../git-compat-util.h"
2 +#undef regcomp
3 +
4 +int git_regcomp(regex_t *preg, const char *pattern, int cflags)
5 +{
6 + if (!(cflags & REG_EXTENDED))
7 + cflags |= REG_ENHANCED;
8 + return regcomp(preg, pattern, cflags);
9 +}
config.mak.uname
+1
@@ -147,6 +147,7 @@ ifeq ($(uname_S),Darwin)
147 FREAD_READS_DIRECTORIES = UnfortunatelyYes
148 HAVE_NS_GET_EXECUTABLE_PATH = YesPlease
149 CSPRNG_METHOD = arc4random
150 + USE_ENHANCED_BASIC_REGULAR_EXPRESSIONS = YesPlease
151
152 # Workaround for `gettext` being keg-only and not even being linked via
153 # `brew link --force gettext`, should be obsolete as of
git-compat-util.h
+5
@@ -1336,6 +1336,11 @@ static inline int regexec_buf(const regex_t *preg, const char *buf, size_t size,
1336 return regexec(preg, buf, nmatch, pmatch, eflags | REG_STARTEND);
1337 }
1338
1339 +#ifdef USE_ENHANCED_BASIC_REGULAR_EXPRESSIONS
1340 +int git_regcomp(regex_t *preg, const char *pattern, int cflags);
1341 +#define regcomp git_regcomp
1342 +#endif
1343 +
1344 #ifndef DIR_HAS_BSD_GROUP_SEMANTICS
1345 # define FORCE_DIR_SET_GID S_ISGID
1346 #else