Skip to content

Commit 5427bb4

Browse files
committed
Merge branch 'rs/use-enhanced-bre-on-macos'
Newer regex library macOS stopped enabling GNU-like enhanced BRE, where '\(A\|B\)' works as alternation, unless explicitly asked with the REG_ENHANCED flag. "git grep" now can be compiled to do so, to retain the old behaviour. * rs/use-enhanced-bre-on-macos: use enhanced basic regular expressions on macOS
2 parents cd37c45 + 54463d3 commit 5427bb4

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
#
@@ -2037,6 +2041,11 @@ endif
20372041
ifdef NO_REGEX
20382042
COMPAT_CFLAGS += -Icompat/regex
20392043
COMPAT_OBJS += compat/regex/regex.o
2044+
else
2045+
ifdef USE_ENHANCED_BASIC_REGULAR_EXPRESSIONS
2046+
COMPAT_CFLAGS += -DUSE_ENHANCED_BASIC_REGULAR_EXPRESSIONS
2047+
COMPAT_OBJS += compat/regcomp_enhanced.o
2048+
endif
20402049
endif
20412050
ifdef NATIVE_CRLF
20422051
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
@@ -1357,6 +1357,11 @@ static inline int regexec_buf(const regex_t *preg, const char *buf, size_t size,
13571357
return regexec(preg, buf, nmatch, pmatch, eflags | REG_STARTEND);
13581358
}
13591359

1360+
#ifdef USE_ENHANCED_BASIC_REGULAR_EXPRESSIONS
1361+
int git_regcomp(regex_t *preg, const char *pattern, int cflags);
1362+
#define regcomp git_regcomp
1363+
#endif
1364+
13601365
#ifndef DIR_HAS_BSD_GROUP_SEMANTICS
13611366
# define FORCE_DIR_SET_GID S_ISGID
13621367
#else

0 commit comments

Comments
 (0)