Merge branch 'rs/use-enhanced-bre-on-macos' into maint-2.39

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
This commit is contained in:
Junio C Hamano 2023-02-14 14:15:49 -08:00
Родитель 11b53f8e52 54463d32ef
Коммит a67610f4ab
4 изменённых файлов: 24 добавлений и 0 удалений

Просмотреть файл

@ -289,6 +289,10 @@ include shared.mak
# Define NO_REGEX if your C library lacks regex support with REG_STARTEND # Define NO_REGEX if your C library lacks regex support with REG_STARTEND
# feature. # feature.
# #
# Define USE_ENHANCED_BASIC_REGULAR_EXPRESSIONS if your C library provides
# the flag REG_ENHANCED and you'd like to use it to enable enhanced basic
# regular expressions.
#
# Define HAVE_DEV_TTY if your system can open /dev/tty to interact with the # Define HAVE_DEV_TTY if your system can open /dev/tty to interact with the
# user. # user.
# #
@ -2040,6 +2044,11 @@ endif
ifdef NO_REGEX ifdef NO_REGEX
COMPAT_CFLAGS += -Icompat/regex COMPAT_CFLAGS += -Icompat/regex
COMPAT_OBJS += compat/regex/regex.o COMPAT_OBJS += compat/regex/regex.o
else
ifdef USE_ENHANCED_BASIC_REGULAR_EXPRESSIONS
COMPAT_CFLAGS += -DUSE_ENHANCED_BASIC_REGULAR_EXPRESSIONS
COMPAT_OBJS += compat/regcomp_enhanced.o
endif
endif endif
ifdef NATIVE_CRLF ifdef NATIVE_CRLF
BASIC_CFLAGS += -DNATIVE_CRLF BASIC_CFLAGS += -DNATIVE_CRLF

Просмотреть файл

@ -0,0 +1,9 @@
#include "../git-compat-util.h"
#undef regcomp
int git_regcomp(regex_t *preg, const char *pattern, int cflags)
{
if (!(cflags & REG_EXTENDED))
cflags |= REG_ENHANCED;
return regcomp(preg, pattern, cflags);
}

Просмотреть файл

@ -147,6 +147,7 @@ ifeq ($(uname_S),Darwin)
FREAD_READS_DIRECTORIES = UnfortunatelyYes FREAD_READS_DIRECTORIES = UnfortunatelyYes
HAVE_NS_GET_EXECUTABLE_PATH = YesPlease HAVE_NS_GET_EXECUTABLE_PATH = YesPlease
CSPRNG_METHOD = arc4random CSPRNG_METHOD = arc4random
USE_ENHANCED_BASIC_REGULAR_EXPRESSIONS = YesPlease
# Workaround for `gettext` being keg-only and not even being linked via # Workaround for `gettext` being keg-only and not even being linked via
# `brew link --force gettext`, should be obsolete as of # `brew link --force gettext`, should be obsolete as of

Просмотреть файл

@ -1346,6 +1346,11 @@ static inline int regexec_buf(const regex_t *preg, const char *buf, size_t size,
return regexec(preg, buf, nmatch, pmatch, eflags | REG_STARTEND); return regexec(preg, buf, nmatch, pmatch, eflags | REG_STARTEND);
} }
#ifdef USE_ENHANCED_BASIC_REGULAR_EXPRESSIONS
int git_regcomp(regex_t *preg, const char *pattern, int cflags);
#define regcomp git_regcomp
#endif
#ifndef DIR_HAS_BSD_GROUP_SEMANTICS #ifndef DIR_HAS_BSD_GROUP_SEMANTICS
# define FORCE_DIR_SET_GID S_ISGID # define FORCE_DIR_SET_GID S_ISGID
#else #else