Skip to content

Commit ae7e4d4

Browse files
committed
Merge branch 'ab/pcre-v2'
Update "perl-compatible regular expression" support to enable JIT and also allow linking with the newer PCRE v2 library. * ab/pcre-v2: grep: add support for PCRE v2 grep: un-break building with PCRE >= 8.32 without --enable-jit grep: un-break building with PCRE < 8.20 grep: un-break building with PCRE < 8.32 grep: add support for the PCRE v1 JIT API log: add -P as a synonym for --perl-regexp grep: skip pthreads overhead when using one thread grep: don't redundantly compile throwaway patterns under threading
2 parents 32e0da5 + 94da919 commit ae7e4d4

File tree

10 files changed

+349
-29
lines changed

10 files changed

+349
-29
lines changed

Documentation/rev-list-options.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ endif::git-rev-list[]
9191
Consider the limiting patterns to be fixed strings (don't interpret
9292
pattern as a regular expression).
9393

94+
-P::
9495
--perl-regexp::
9596
Consider the limiting patterns to be Perl-compatible regular
9697
expressions.

Makefile

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,23 @@ all::
2929
# Perl-compatible regular expressions instead of standard or extended
3030
# POSIX regular expressions.
3131
#
32-
# Define LIBPCREDIR=/foo/bar if your libpcre header and library files are in
33-
# /foo/bar/include and /foo/bar/lib directories.
32+
# Currently USE_LIBPCRE is a synonym for USE_LIBPCRE1, define
33+
# USE_LIBPCRE2 instead if you'd like to use version 2 of the PCRE
34+
# library. The USE_LIBPCRE flag will likely be changed to mean v2 by
35+
# default in future releases.
36+
#
37+
# When using USE_LIBPCRE1, define NO_LIBPCRE1_JIT if the PCRE v1
38+
# library is compiled without --enable-jit. We will auto-detect
39+
# whether the version of the PCRE v1 library in use has JIT support at
40+
# all, but we unfortunately can't auto-detect whether JIT support
41+
# hasn't been compiled in in an otherwise JIT-supporting version. If
42+
# you have link-time errors about a missing `pcre_jit_exec` define
43+
# this, or recompile PCRE v1 with --enable-jit.
44+
#
45+
# Define LIBPCREDIR=/foo/bar if your PCRE header and library files are
46+
# in /foo/bar/include and /foo/bar/lib directories. Which version of
47+
# PCRE this points to determined by the USE_LIBPCRE1 and USE_LIBPCRE2
48+
# variables.
3449
#
3550
# Define HAVE_ALLOCA_H if you have working alloca(3) defined in that header.
3651
#
@@ -1089,13 +1104,29 @@ ifdef NO_LIBGEN_H
10891104
COMPAT_OBJS += compat/basename.o
10901105
endif
10911106

1092-
ifdef USE_LIBPCRE
1093-
BASIC_CFLAGS += -DUSE_LIBPCRE1
1094-
ifdef LIBPCREDIR
1095-
BASIC_CFLAGS += -I$(LIBPCREDIR)/include
1096-
EXTLIBS += -L$(LIBPCREDIR)/$(lib) $(CC_LD_DYNPATH)$(LIBPCREDIR)/$(lib)
1107+
USE_LIBPCRE1 ?= $(USE_LIBPCRE)
1108+
1109+
ifneq (,$(USE_LIBPCRE1))
1110+
ifdef USE_LIBPCRE2
1111+
$(error Only set USE_LIBPCRE1 (or its alias USE_LIBPCRE) or USE_LIBPCRE2, not both!)
10971112
endif
1113+
1114+
BASIC_CFLAGS += -DUSE_LIBPCRE1
10981115
EXTLIBS += -lpcre
1116+
1117+
ifdef NO_LIBPCRE1_JIT
1118+
BASIC_CFLAGS += -DNO_LIBPCRE1_JIT
1119+
endif
1120+
endif
1121+
1122+
ifdef USE_LIBPCRE2
1123+
BASIC_CFLAGS += -DUSE_LIBPCRE2
1124+
EXTLIBS += -lpcre2-8
1125+
endif
1126+
1127+
ifdef LIBPCREDIR
1128+
BASIC_CFLAGS += -I$(LIBPCREDIR)/include
1129+
EXTLIBS += -L$(LIBPCREDIR)/$(lib) $(CC_LD_DYNPATH)$(LIBPCREDIR)/$(lib)
10991130
endif
11001131

11011132
ifdef HAVE_ALLOCA_H
@@ -2249,7 +2280,9 @@ GIT-BUILD-OPTIONS: FORCE
22492280
@echo TAR=\''$(subst ','\'',$(subst ','\'',$(TAR)))'\' >>$@+
22502281
@echo NO_CURL=\''$(subst ','\'',$(subst ','\'',$(NO_CURL)))'\' >>$@+
22512282
@echo NO_EXPAT=\''$(subst ','\'',$(subst ','\'',$(NO_EXPAT)))'\' >>$@+
2252-
@echo USE_LIBPCRE1=\''$(subst ','\'',$(subst ','\'',$(USE_LIBPCRE)))'\' >>$@+
2283+
@echo USE_LIBPCRE1=\''$(subst ','\'',$(subst ','\'',$(USE_LIBPCRE1)))'\' >>$@+
2284+
@echo USE_LIBPCRE2=\''$(subst ','\'',$(subst ','\'',$(USE_LIBPCRE2)))'\' >>$@+
2285+
@echo NO_LIBPCRE1_JIT=\''$(subst ','\'',$(subst ','\'',$(NO_LIBPCRE1_JIT)))'\' >>$@+
22532286
@echo NO_PERL=\''$(subst ','\'',$(subst ','\'',$(NO_PERL)))'\' >>$@+
22542287
@echo NO_PTHREADS=\''$(subst ','\'',$(subst ','\'',$(NO_PTHREADS)))'\' >>$@+
22552288
@echo NO_PYTHON=\''$(subst ','\'',$(subst ','\'',$(NO_PYTHON)))'\' >>$@+

builtin/grep.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ static void start_threads(struct grep_opt *opt)
224224
int err;
225225
struct grep_opt *o = grep_opt_dup(opt);
226226
o->output = strbuf_out;
227-
o->debug = 0;
227+
if (i)
228+
o->debug = 0;
228229
compile_grep_patterns(o);
229230
err = pthread_create(&threads[i], NULL, run, o);
230231

@@ -1170,8 +1171,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
11701171
if (!opt.fixed && opt.ignore_case)
11711172
opt.regflags |= REG_ICASE;
11721173

1173-
compile_grep_patterns(&opt);
1174-
11751174
/*
11761175
* We have to find "--" in a separate pass, because its presence
11771176
* influences how we will parse arguments that come before it.
@@ -1244,12 +1243,23 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
12441243
num_threads = GREP_NUM_THREADS_DEFAULT;
12451244
else if (num_threads < 0)
12461245
die(_("invalid number of threads specified (%d)"), num_threads);
1246+
if (num_threads == 1)
1247+
num_threads = 0;
12471248
#else
12481249
if (num_threads)
12491250
warning(_("no threads support, ignoring --threads"));
12501251
num_threads = 0;
12511252
#endif
12521253

1254+
if (!num_threads)
1255+
/*
1256+
* The compiled patterns on the main path are only
1257+
* used when not using threading. Otherwise
1258+
* start_threads() below calls compile_grep_patterns()
1259+
* for each thread.
1260+
*/
1261+
compile_grep_patterns(&opt);
1262+
12531263
#ifndef NO_PTHREADS
12541264
if (num_threads) {
12551265
if (!(opt.name_only || opt.unmatch_name_only || opt.count)

config.mak.uname

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ else
555555
NO_GETTEXT =
556556
USE_GETTEXT_SCHEME = fallthrough
557557
USE_LIBPCRE= YesPlease
558+
NO_LIBPCRE1_JIT = UnfortunatelyYes
558559
NO_CURL =
559560
USE_NED_ALLOCATOR = YesPlease
560561
else

configure.ac

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -255,21 +255,61 @@ GIT_PARSE_WITH([openssl]))
255255
# Perl-compatible regular expressions instead of standard or extended
256256
# POSIX regular expressions.
257257
#
258-
# Define LIBPCREDIR=/foo/bar if your libpcre header and library files are in
258+
# Currently USE_LIBPCRE is a synonym for USE_LIBPCRE1, define
259+
# USE_LIBPCRE2 instead if you'd like to use version 2 of the PCRE
260+
# library. The USE_LIBPCRE flag will likely be changed to mean v2 by
261+
# default in future releases.
262+
#
263+
# Define LIBPCREDIR=/foo/bar if your PCRE header and library files are in
259264
# /foo/bar/include and /foo/bar/lib directories.
260265
#
261266
AC_ARG_WITH(libpcre,
262-
AS_HELP_STRING([--with-libpcre],[support Perl-compatible regexes (default is NO)])
267+
AS_HELP_STRING([--with-libpcre],[synonym for --with-libpcre1]),
268+
if test "$withval" = "no"; then
269+
USE_LIBPCRE1=
270+
elif test "$withval" = "yes"; then
271+
USE_LIBPCRE1=YesPlease
272+
else
273+
USE_LIBPCRE1=YesPlease
274+
LIBPCREDIR=$withval
275+
AC_MSG_NOTICE([Setting LIBPCREDIR to $LIBPCREDIR])
276+
dnl USE_LIBPCRE1 can still be modified below, so don't substitute
277+
dnl it yet.
278+
GIT_CONF_SUBST([LIBPCREDIR])
279+
fi)
280+
281+
AC_ARG_WITH(libpcre1,
282+
AS_HELP_STRING([--with-libpcre1],[support Perl-compatible regexes via libpcre1 (default is NO)])
283+
AS_HELP_STRING([], [ARG can be also prefix for libpcre library and headers]),
284+
if test "$withval" = "no"; then
285+
USE_LIBPCRE1=
286+
elif test "$withval" = "yes"; then
287+
USE_LIBPCRE1=YesPlease
288+
else
289+
USE_LIBPCRE1=YesPlease
290+
LIBPCREDIR=$withval
291+
AC_MSG_NOTICE([Setting LIBPCREDIR to $LIBPCREDIR])
292+
dnl USE_LIBPCRE1 can still be modified below, so don't substitute
293+
dnl it yet.
294+
GIT_CONF_SUBST([LIBPCREDIR])
295+
fi)
296+
297+
AC_ARG_WITH(libpcre2,
298+
AS_HELP_STRING([--with-libpcre2],[support Perl-compatible regexes via libpcre2 (default is NO)])
263299
AS_HELP_STRING([], [ARG can be also prefix for libpcre library and headers]),
300+
if test -n "$USE_LIBPCRE1"; then
301+
AC_MSG_ERROR([Only supply one of --with-libpcre1 or --with-libpcre2!])
302+
fi
303+
264304
if test "$withval" = "no"; then
265-
USE_LIBPCRE=
305+
USE_LIBPCRE2=
266306
elif test "$withval" = "yes"; then
267-
USE_LIBPCRE=YesPlease
307+
USE_LIBPCRE2=YesPlease
268308
else
269-
USE_LIBPCRE=YesPlease
309+
USE_LIBPCRE2=YesPlease
270310
LIBPCREDIR=$withval
271311
AC_MSG_NOTICE([Setting LIBPCREDIR to $LIBPCREDIR])
272-
dnl USE_LIBPCRE can still be modified below, so don't substitute
312+
dnl USE_LIBPCRE2 can still be modified below, so don't substitute
273313
dnl it yet.
274314
GIT_CONF_SUBST([LIBPCREDIR])
275315
fi)
@@ -501,13 +541,11 @@ GIT_CONF_SUBST([NEEDS_SSL_WITH_CRYPTO])
501541
GIT_CONF_SUBST([NO_OPENSSL])
502542

503543
#
504-
# Define USE_LIBPCRE if you have and want to use libpcre. Various
505-
# commands such as log and grep offer runtime options to use
506-
# Perl-compatible regular expressions instead of standard or extended
507-
# POSIX regular expressions.
544+
# Handle the USE_LIBPCRE1 and USE_LIBPCRE2 options potentially set
545+
# above.
508546
#
509547

510-
if test -n "$USE_LIBPCRE"; then
548+
if test -n "$USE_LIBPCRE1"; then
511549

512550
GIT_STASH_FLAGS($LIBPCREDIR)
513551

@@ -517,7 +555,22 @@ AC_CHECK_LIB([pcre], [pcre_version],
517555

518556
GIT_UNSTASH_FLAGS($LIBPCREDIR)
519557

520-
GIT_CONF_SUBST([USE_LIBPCRE])
558+
GIT_CONF_SUBST([USE_LIBPCRE1])
559+
560+
fi
561+
562+
563+
if test -n "$USE_LIBPCRE2"; then
564+
565+
GIT_STASH_FLAGS($LIBPCREDIR)
566+
567+
AC_CHECK_LIB([pcre2-8], [pcre2_config_8],
568+
[USE_LIBPCRE2=YesPlease],
569+
[USE_LIBPCRE2=])
570+
571+
GIT_UNSTASH_FLAGS($LIBPCREDIR)
572+
573+
GIT_CONF_SUBST([USE_LIBPCRE2])
521574

522575
fi
523576

0 commit comments

Comments
 (0)