Skip to content

Commit 54463d3

Browse files
rscharfegitster
authored andcommitted
use enhanced basic regular expressions on macOS
When 1819ad3 (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 <[email protected]> Suggested-by: Jeff King <[email protected]> Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c48035d commit 54463d3

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ include shared.mak
289289
# Define NO_REGEX if your C library lacks regex support with REG_STARTEND
290290
# feature.
291291
#
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+
#
292296
# Define HAVE_DEV_TTY if your system can open /dev/tty to interact with the
293297
# user.
294298
#
@@ -2040,6 +2044,11 @@ endif
20402044
ifdef NO_REGEX
20412045
COMPAT_CFLAGS += -Icompat/regex
20422046
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
20432052
endif
20442053
ifdef NATIVE_CRLF
20452054
BASIC_CFLAGS += -DNATIVE_CRLF

compat/regcomp_enhanced.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ ifeq ($(uname_S),Darwin)
147147
FREAD_READS_DIRECTORIES = UnfortunatelyYes
148148
HAVE_NS_GET_EXECUTABLE_PATH = YesPlease
149149
CSPRNG_METHOD = arc4random
150+
USE_ENHANCED_BASIC_REGULAR_EXPRESSIONS = YesPlease
150151

151152
# Workaround for `gettext` being keg-only and not even being linked via
152153
# `brew link --force gettext`, should be obsolete as of

git-compat-util.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,11 @@ static inline int regexec_buf(const regex_t *preg, const char *buf, size_t size,
13361336
return regexec(preg, buf, nmatch, pmatch, eflags | REG_STARTEND);
13371337
}
13381338

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+
13391344
#ifndef DIR_HAS_BSD_GROUP_SEMANTICS
13401345
# define FORCE_DIR_SET_GID S_ISGID
13411346
#else

0 commit comments

Comments
 (0)