summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2023-01-23 21:39:51 (GMT)
committerJunio C Hamano <gitster@pobox.com>2023-01-23 21:39:51 (GMT)
commit5427bb4893e29a9502bbee5aed84c3b26e1a4e15 (patch)
tree9e8a02d927e20bc6259919e42f338d82cbca689d
parentcd37c45acf8170aa80a4d7bd44ea5fc8241047f2 (diff)
parent54463d32ef6798c772c8bbf69b2c1897a854db9f (diff)
downloadgit-5427bb4893e29a9502bbee5aed84c3b26e1a4e15.zip
git-5427bb4893e29a9502bbee5aed84c3b26e1a4e15.tar.gz
git-5427bb4893e29a9502bbee5aed84c3b26e1a4e15.tar.bz2
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
-rw-r--r--Makefile9
-rw-r--r--compat/regcomp_enhanced.c9
-rw-r--r--config.mak.uname1
-rw-r--r--git-compat-util.h5
4 files changed, 24 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index e077c9b..45bd6ac 100644
--- a/Makefile
+++ b/Makefile
@@ -289,6 +289,10 @@ include shared.mak
# Define NO_REGEX if your C library lacks regex support with REG_STARTEND
# 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
# user.
#
@@ -2037,6 +2041,11 @@ endif
ifdef NO_REGEX
COMPAT_CFLAGS += -Icompat/regex
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
ifdef NATIVE_CRLF
BASIC_CFLAGS += -DNATIVE_CRLF
diff --git a/compat/regcomp_enhanced.c b/compat/regcomp_enhanced.c
new file mode 100644
index 0000000..84193ce
--- /dev/null
+++ b/compat/regcomp_enhanced.c
@@ -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);
+}
diff --git a/config.mak.uname b/config.mak.uname
index d63629f..7d25995 100644
--- a/config.mak.uname
+++ b/config.mak.uname
@@ -147,6 +147,7 @@ ifeq ($(uname_S),Darwin)
FREAD_READS_DIRECTORIES = UnfortunatelyYes
HAVE_NS_GET_EXECUTABLE_PATH = YesPlease
CSPRNG_METHOD = arc4random
+ USE_ENHANCED_BASIC_REGULAR_EXPRESSIONS = YesPlease
# Workaround for `gettext` being keg-only and not even being linked via
# `brew link --force gettext`, should be obsolete as of
diff --git a/git-compat-util.h b/git-compat-util.h
index 6240fc0..4f0028c 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -1357,6 +1357,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);
}
+#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
# define FORCE_DIR_SET_GID S_ISGID
#else