Skip to content

Commit 119a514

Browse files
committed
Merge branch 'ab/grep-pcre-v2' into pu
PCRE2, which has an API different from and incompatible with PCRE, can now be chosen to support "grep -P -e '<pattern>'" and friends. * ab/grep-pcre-v2: SQUASH??? Makefile & configure: make PCRE v2 the default PCRE implementation grep: remove support for concurrent use of both PCRE v1 & v2 grep: add support for PCRE v2 grep: add support for the PCRE v1 JIT API perf: add a performance comparison test of grep -E and -P grep: change the internal PCRE code & header names to be PCRE1 grep: change the internal PCRE macro names to be PCRE1 test-lib: rename the LIBPCRE prerequisite to PCRE grep: make grep.patternType=[pcre|pcre1] a synonym for "perl" grep & rev-list doc: stop promising libpcre for --perl-regexp log: add -P as a synonym for --perl-regexp log: add exhaustive tests for pattern style options & config grep: add a test for backreferences in PCRE patterns Makefile & configure: reword outdated comment about PCRE grep: remove redundant `regflags &= ~REG_EXTENDED` assignments grep: remove redundant regflags assignment under PCRE grep: submodule-related case statements should die if new fields are added grep: add tests for grep pattern types being passed to submodules grep: amend submodule recursion test in preparation for rx engine testing
2 parents db81e1c + 4f21b99 commit 119a514

16 files changed

+614
-173
lines changed

Documentation/git-grep.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,11 @@ OPTIONS
161161

162162
-P::
163163
--perl-regexp::
164-
Use Perl-compatible regexp for patterns. Requires libpcre to be
165-
compiled in.
164+
Use Perl-compatible regular expressions for patterns.
165+
+
166+
Support for these types of regular expressions is an optional
167+
compile-time dependency. If Git wasn't compiled with support for them
168+
providing this option will cause it to die.
166169

167170
-F::
168171
--fixed-strings::

Documentation/rev-list-options.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,14 @@ 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::
95-
Consider the limiting patterns to be Perl-compatible regular expressions.
96-
Requires libpcre to be compiled in.
96+
Consider the limiting patterns to be Perl-compatible regular
97+
expressions.
98+
+
99+
Support for these types of regular expressions is an optional
100+
compile-time dependency. If Git wasn't compiled with support for them
101+
providing this option will cause it to die.
97102

98103
--remove-empty::
99104
Stop when a given path disappears from the tree.

Makefile

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,17 @@ all::
2424
# Define NO_OPENSSL environment variable if you do not have OpenSSL.
2525
# This also implies BLK_SHA1.
2626
#
27-
# Define USE_LIBPCRE if you have and want to use libpcre. git-grep will be
28-
# able to use Perl-compatible regular expressions.
27+
# Define USE_LIBPCRE if you have and want to use libpcre. Various
28+
# commands such as log and grep offer runtime options to use
29+
# Perl-compatible regular expressions instead of standard or extended
30+
# POSIX regular expressions.
2931
#
30-
# Define LIBPCREDIR=/foo/bar if your libpcre header and library files are in
32+
# The USE_LIBPCRE flag is a synonym for USE_LIBPCRE2, in previous
33+
# versions it meant the same thing USE_LIBPCRE1 does now. Define
34+
# USE_LIBPCRE1 instead if you'd like to use the legacy version 1 of
35+
# the PCRE library.
36+
#
37+
# Define LIBPCREDIR=/foo/bar if your PCRE header and library files are in
3138
# /foo/bar/include and /foo/bar/lib directories.
3239
#
3340
# Define HAVE_ALLOCA_H if you have working alloca(3) defined in that header.
@@ -1087,15 +1094,26 @@ ifdef NO_LIBGEN_H
10871094
COMPAT_OBJS += compat/basename.o
10881095
endif
10891096

1090-
ifdef USE_LIBPCRE
1091-
BASIC_CFLAGS += -DUSE_LIBPCRE
1092-
ifdef LIBPCREDIR
1093-
BASIC_CFLAGS += -I$(LIBPCREDIR)/include
1094-
EXTLIBS += -L$(LIBPCREDIR)/$(lib) $(CC_LD_DYNPATH)$(LIBPCREDIR)/$(lib)
1095-
endif
1097+
USE_LIBPCRE2 ?= $(USE_LIBPCRE)
1098+
1099+
ifdef USE_LIBPCRE1
1100+
BASIC_CFLAGS += -DUSE_LIBPCRE1
10961101
EXTLIBS += -lpcre
10971102
endif
10981103

1104+
ifneq (,$(USE_LIBPCRE2))
1105+
ifdef USE_LIBPCRE1
1106+
$(error Only set USE_LIBPCRE2 (or its alias USE_LIBPCRE) or USE_LIBPCRE1, not both!)
1107+
endif
1108+
BASIC_CFLAGS += -DUSE_LIBPCRE2
1109+
EXTLIBS += -lpcre2-8
1110+
endif
1111+
1112+
ifdef LIBPCREDIR
1113+
BASIC_CFLAGS += -I$(LIBPCREDIR)/include
1114+
EXTLIBS += -L$(LIBPCREDIR)/$(lib) $(CC_LD_DYNPATH)$(LIBPCREDIR)/$(lib)
1115+
endif
1116+
10991117
ifdef HAVE_ALLOCA_H
11001118
BASIC_CFLAGS += -DHAVE_ALLOCA_H
11011119
endif
@@ -2240,7 +2258,8 @@ GIT-BUILD-OPTIONS: FORCE
22402258
@echo TAR=\''$(subst ','\'',$(subst ','\'',$(TAR)))'\' >>$@+
22412259
@echo NO_CURL=\''$(subst ','\'',$(subst ','\'',$(NO_CURL)))'\' >>$@+
22422260
@echo NO_EXPAT=\''$(subst ','\'',$(subst ','\'',$(NO_EXPAT)))'\' >>$@+
2243-
@echo USE_LIBPCRE=\''$(subst ','\'',$(subst ','\'',$(USE_LIBPCRE)))'\' >>$@+
2261+
@echo USE_LIBPCRE1=\''$(subst ','\'',$(subst ','\'',$(USE_LIBPCRE)))'\' >>$@+
2262+
@echo USE_LIBPCRE2=\''$(subst ','\'',$(subst ','\'',$(USE_LIBPCRE2)))'\' >>$@+
22442263
@echo NO_PERL=\''$(subst ','\'',$(subst ','\'',$(NO_PERL)))'\' >>$@+
22452264
@echo NO_PTHREADS=\''$(subst ','\'',$(subst ','\'',$(NO_PTHREADS)))'\' >>$@+
22462265
@echo NO_PYTHON=\''$(subst ','\'',$(subst ','\'',$(NO_PYTHON)))'\' >>$@+

builtin/grep.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,8 @@ static void compile_submodule_options(const struct grep_opt *opt,
502502
break;
503503
case GREP_PATTERN_TYPE_UNSPECIFIED:
504504
break;
505+
default:
506+
die("BUG: Added a new grep pattern type without updating switch statement");
505507
}
506508

507509
for (pattern = opt->pattern_list; pattern != NULL;
@@ -522,6 +524,8 @@ static void compile_submodule_options(const struct grep_opt *opt,
522524
case GREP_PATTERN_BODY:
523525
case GREP_PATTERN_HEAD:
524526
break;
527+
default:
528+
die("BUG: Added a new grep token type without updating case statement");
525529
}
526530
}
527531

configure.ac

Lines changed: 69 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -250,24 +250,66 @@ AS_HELP_STRING([--with-openssl],[use OpenSSL library (default is YES)])
250250
AS_HELP_STRING([], [ARG can be prefix for openssl library and headers]),
251251
GIT_PARSE_WITH([openssl]))
252252

253-
# Define USE_LIBPCRE if you have and want to use libpcre. git-grep will be
254-
# able to use Perl-compatible regular expressions.
253+
# Define USE_LIBPCRE if you have and want to use libpcre. Various
254+
# commands such as log and grep offer runtime options to use
255+
# Perl-compatible regular expressions instead of standard or extended
256+
# POSIX regular expressions.
255257
#
256-
# Define LIBPCREDIR=/foo/bar if your libpcre header and library files are in
258+
# The USE_LIBPCRE flag is a synonym for USE_LIBPCRE2, in previous
259+
# versions it meant the same thing USE_LIBPCRE1 does now. Define
260+
# USE_LIBPCRE1 instead if you'd like to use the legacy version 1 of
261+
# the PCRE library.
262+
#
263+
# Define LIBPCREDIR=/foo/bar if your PCRE header and library files are in
257264
# /foo/bar/include and /foo/bar/lib directories.
258265
#
259266
AC_ARG_WITH(libpcre,
260-
AS_HELP_STRING([--with-libpcre],[support Perl-compatible regexes (default is NO)])
267+
AS_HELP_STRING([--with-libpcre],[synonym for --with-libpcre2]),
268+
if test "$withval" = "no"; then
269+
USE_LIBPCRE2=
270+
elif test "$withval" = "yes"; then
271+
USE_LIBPCRE2=YesPlease
272+
else
273+
USE_LIBPCRE2=YesPlease
274+
LIBPCREDIR=$withval
275+
AC_MSG_NOTICE([Setting LIBPCREDIR to $LIBPCREDIR])
276+
dnl USE_LIBPCRE2 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)])
261299
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+
262304
if test "$withval" = "no"; then
263-
USE_LIBPCRE=
305+
USE_LIBPCRE2=
264306
elif test "$withval" = "yes"; then
265-
USE_LIBPCRE=YesPlease
307+
USE_LIBPCRE2=YesPlease
266308
else
267-
USE_LIBPCRE=YesPlease
309+
USE_LIBPCRE2=YesPlease
268310
LIBPCREDIR=$withval
269311
AC_MSG_NOTICE([Setting LIBPCREDIR to $LIBPCREDIR])
270-
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
271313
dnl it yet.
272314
GIT_CONF_SUBST([LIBPCREDIR])
273315
fi)
@@ -499,11 +541,11 @@ GIT_CONF_SUBST([NEEDS_SSL_WITH_CRYPTO])
499541
GIT_CONF_SUBST([NO_OPENSSL])
500542

501543
#
502-
# Define USE_LIBPCRE if you have and want to use libpcre. git-grep will be
503-
# able to use Perl-compatible regular expressions.
544+
# Handle the USE_LIBPCRE1 and USE_LIBPCRE2 options potentially set
545+
# above.
504546
#
505547

506-
if test -n "$USE_LIBPCRE"; then
548+
if test -n "$USE_LIBPCRE1"; then
507549

508550
GIT_STASH_FLAGS($LIBPCREDIR)
509551

@@ -513,7 +555,22 @@ AC_CHECK_LIB([pcre], [pcre_version],
513555

514556
GIT_UNSTASH_FLAGS($LIBPCREDIR)
515557

516-
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])
517574

518575
fi
519576

0 commit comments

Comments
 (0)