]> git.ipfire.org Git - thirdparty/git.git/commitdiff
use enhanced basic regular expressions on macOS
authorRené Scharfe <l.s.r@web.de>
Sun, 8 Jan 2023 00:42:04 +0000 (01:42 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sun, 8 Jan 2023 01:06:34 +0000 (10:06 +0900)
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>
Makefile
compat/regcomp_enhanced.c [new file with mode: 0644]
config.mak.uname
git-compat-util.h

index b258fdbed8623d44b014d3ec0dde0350ecb73d43..093829ae2832aa1f94e6d3c8caca7c15112fb0f2 100644 (file)
--- 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.
 #
@@ -2040,6 +2044,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 (file)
index 0000000..84193ce
--- /dev/null
@@ -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);
+}
index d63629fe807f59deda80ed780c1915df011bf862..7d259952652291eb9c3aba161a9f710be8ada8f5 100644 (file)
@@ -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
index a76d0526f79266e1dc512072a4236876df8f8726..4824c8cad40bc258cd0a1c978794f6a179557d8d 100644 (file)
@@ -1336,6 +1336,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