Remove support for v1 of the PCRE library

Remove support for using version 1 of the PCRE library. Its use has been discouraged by upstream for a long time, and it's in a bugfix-only state. Anyone who was relying on v1 in particular got a nudge to move to v2 in e6c531b808 (Makefile: make USE_LIBPCRE=YesPlease mean v2, not v1, 2018-03-11), which was first released as part of v2.18.0. With this the LIBPCRE2 test prerequisites is redundant to PCRE. But I'm keeping it for self-documentation purposes, and to avoid conflict with other in-flight PCRE patches. I'm also not changing all of our own "pcre2" names to "pcre", i.e. the inverse of 6d4b5747f0 (grep: change internal *pcre* variable & function names to be *pcre1*, 2017-05-25). I don't see the point, and it makes the history/blame harder to read. Maybe if there's ever a PCRE v3... Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Jan 24, 2021 at 02:58 UTC 7599730b7e2be694142bfb2e95187afa78a5404a
7 files changed +18 -217
Makefile
+7 -25
@@ -29,18 +29,11 @@ all::
29 # Perl-compatible regular expressions instead of standard or extended
30 # POSIX regular expressions.
31 #
32 -# USE_LIBPCRE is a synonym for USE_LIBPCRE2, define USE_LIBPCRE1
33 -# instead if you'd like to use the legacy version 1 of the PCRE
34 -# library. Support for version 1 will likely be removed in some future
35 -# release of Git, as upstream has all but abandoned it.
36 -#
37 -# When using USE_LIBPCRE1, define NO_LIBPCRE1_JIT if you want to
38 -# disable JIT even if supported by your library.
32 +# Only libpcre version 2 is supported. USE_LIBPCRE2 is a synonym for
33 +# USE_LIBPCRE, support for the old USE_LIBPCRE1 has been removed.
34 #
35 # Define LIBPCREDIR=/foo/bar if your PCRE header and library files are
41 -# in /foo/bar/include and /foo/bar/lib directories. Which version of
42 -# PCRE this points to determined by the USE_LIBPCRE1 and USE_LIBPCRE2
43 -# variables.
36 +# in /foo/bar/include and /foo/bar/lib directories.
37 #
38 # Define HAVE_ALLOCA_H if you have working alloca(3) defined in that header.
39 #
@@ -1359,26 +1352,17 @@ ifdef NO_LIBGEN_H
1352 COMPAT_OBJS += compat/basename.o
1353 endif
1354
1355 +ifdef USE_LIBPCRE1
1356 +$(error The USE_LIBPCRE1 build option has been removed, use version 2 with USE_LIBPCRE)
1357 +endif
1358 +
1359 USE_LIBPCRE2 ?= $(USE_LIBPCRE)
1360
1361 ifneq (,$(USE_LIBPCRE2))
1365 - ifdef USE_LIBPCRE1
1366 -$(error Only set USE_LIBPCRE2 (or its alias USE_LIBPCRE) or USE_LIBPCRE1, not both!)
1367 - endif
1368 -
1362 BASIC_CFLAGS += -DUSE_LIBPCRE2
1363 EXTLIBS += -lpcre2-8
1364 endif
1365
1373 -ifdef USE_LIBPCRE1
1374 - BASIC_CFLAGS += -DUSE_LIBPCRE1
1375 - EXTLIBS += -lpcre
1376 -
1377 -ifdef NO_LIBPCRE1_JIT
1378 - BASIC_CFLAGS += -DNO_LIBPCRE1_JIT
1379 -endif
1380 -endif
1381 -
1366 ifdef LIBPCREDIR
1367 BASIC_CFLAGS += -I$(LIBPCREDIR)/include
1368 EXTLIBS += -L$(LIBPCREDIR)/$(lib) $(CC_LD_DYNPATH)$(LIBPCREDIR)/$(lib)
@@ -2726,9 +2710,7 @@ GIT-BUILD-OPTIONS: FORCE
2710 @echo TAR=\''$(subst ','\'',$(subst ','\'',$(TAR)))'\' >>$@+
2711 @echo NO_CURL=\''$(subst ','\'',$(subst ','\'',$(NO_CURL)))'\' >>$@+
2712 @echo NO_EXPAT=\''$(subst ','\'',$(subst ','\'',$(NO_EXPAT)))'\' >>$@+
2729 - @echo USE_LIBPCRE1=\''$(subst ','\'',$(subst ','\'',$(USE_LIBPCRE1)))'\' >>$@+
2713 @echo USE_LIBPCRE2=\''$(subst ','\'',$(subst ','\'',$(USE_LIBPCRE2)))'\' >>$@+
2731 - @echo NO_LIBPCRE1_JIT=\''$(subst ','\'',$(subst ','\'',$(NO_LIBPCRE1_JIT)))'\' >>$@+
2714 @echo NO_PERL=\''$(subst ','\'',$(subst ','\'',$(NO_PERL)))'\' >>$@+
2715 @echo NO_PTHREADS=\''$(subst ','\'',$(subst ','\'',$(NO_PTHREADS)))'\' >>$@+
2716 @echo NO_PYTHON=\''$(subst ','\'',$(subst ','\'',$(NO_PYTHON)))'\' >>$@+
configure.ac
+8 -43
@@ -252,16 +252,17 @@ GIT_PARSE_WITH([openssl]))
252 # Define USE_LIBPCRE if you have and want to use libpcre. Various
253 # commands such as log and grep offer runtime options to use
254 # Perl-compatible regular expressions instead of standard or extended
255 -# POSIX regular expressions.
256 -#
257 -# USE_LIBPCRE is a synonym for USE_LIBPCRE2, define USE_LIBPCRE1
258 -# instead if you'd like to use the legacy version 1 of the PCRE
259 -# library. Support for version 1 will likely be removed in some future
260 -# release of Git, as upstream has all but abandoned it.
255 +# POSIX regular expressions. Only libpcre version 2 is supported.
256 #
257 # Define LIBPCREDIR=/foo/bar if your PCRE header and library files are in
258 # /foo/bar/include and /foo/bar/lib directories.
259 #
260 +
261 +AC_ARG_WITH(libpcre1,
262 +AS_HELP_STRING([--with-libpcre1],[DEPRECATED]),
263 + AC_MSG_ERROR([support for --with-libpcre1 has been removed. Use --with-libpcre2!])
264 + )
265 +
266 AC_ARG_WITH(libpcre,
267 AS_HELP_STRING([--with-libpcre],[synonym for --with-libpcre2]),
268 if test "$withval" = "no"; then
@@ -277,22 +278,6 @@ AS_HELP_STRING([--with-libpcre],[synonym for --with-libpcre2]),
278 GIT_CONF_SUBST([LIBPCREDIR])
279 fi)
280
280 -AC_ARG_WITH(libpcre1,
281 -AS_HELP_STRING([--with-libpcre1],[support Perl-compatible regexes via libpcre1 (default is NO)])
282 -AS_HELP_STRING([], [ARG can be also prefix for libpcre library and headers]),
283 - if test "$withval" = "no"; then
284 - USE_LIBPCRE1=
285 - elif test "$withval" = "yes"; then
286 - USE_LIBPCRE1=YesPlease
287 - else
288 - USE_LIBPCRE1=YesPlease
289 - LIBPCREDIR=$withval
290 - AC_MSG_NOTICE([Setting LIBPCREDIR to $LIBPCREDIR])
291 - dnl USE_LIBPCRE1 can still be modified below, so don't substitute
292 - dnl it yet.
293 - GIT_CONF_SUBST([LIBPCREDIR])
294 - fi)
295 -
281 AC_ARG_WITH(libpcre2,
282 AS_HELP_STRING([--with-libpcre2],[support Perl-compatible regexes via libpcre2 (default is NO)])
283 AS_HELP_STRING([], [ARG can be also prefix for libpcre library and headers]),
@@ -300,10 +285,6 @@ AS_HELP_STRING([], [ARG can be also prefix for libpcre library and hea
285 AC_MSG_ERROR([Only supply one of --with-libpcre or its synonym --with-libpcre2!])
286 fi
287
303 - if test -n "$USE_LIBPCRE1"; then
304 - AC_MSG_ERROR([Only supply one of --with-libpcre1 or --with-libpcre2!])
305 - fi
306 -
288 if test "$withval" = "no"; then
289 USE_LIBPCRE2=
290 elif test "$withval" = "yes"; then
@@ -554,25 +535,9 @@ GIT_CONF_SUBST([NEEDS_SSL_WITH_CRYPTO])
535 GIT_CONF_SUBST([NO_OPENSSL])
536
537 #
557 -# Handle the USE_LIBPCRE1 and USE_LIBPCRE2 options potentially set
558 -# above.
538 +# Handle the USE_LIBPCRE options potentially set above.
539 #
540
561 -if test -n "$USE_LIBPCRE1"; then
562 -
563 -GIT_STASH_FLAGS($LIBPCREDIR)
564 -
565 -AC_CHECK_LIB([pcre], [pcre_version],
566 -[USE_LIBPCRE1=YesPlease],
567 -[USE_LIBPCRE1=])
568 -
569 -GIT_UNSTASH_FLAGS($LIBPCREDIR)
570 -
571 -GIT_CONF_SUBST([USE_LIBPCRE1])
572 -
573 -fi
574 -
575 -
541 if test -n "$USE_LIBPCRE2"; then
542
543 GIT_STASH_FLAGS($LIBPCREDIR)
contrib/buildsystems/CMakeLists.txt
-4
@@ -910,9 +910,7 @@ set(PYTHON_PATH /usr/bin/python)
910 set(TAR tar)
911 set(NO_CURL )
912 set(NO_EXPAT )
913 -set(USE_LIBPCRE1 )
913 set(USE_LIBPCRE2 )
915 -set(NO_LIBPCRE1_JIT )
914 set(NO_PERL )
915 set(NO_PTHREADS )
916 set(NO_PYTHON )
@@ -949,8 +947,6 @@ file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "PYTHON_PATH='${PYTHON_PATH}'\
947 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "TAR='${TAR}'\n")
948 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_CURL='${NO_CURL}'\n")
949 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_EXPAT='${NO_EXPAT}'\n")
952 -file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "USE_LIBPCRE1='${USE_LIBPCRE1}'\n")
953 -file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_LIBPCRE1_JIT='${NO_LIBPCRE1_JIT}'\n")
950 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PERL='${NO_PERL}'\n")
951 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_PTHREADS='${NO_PTHREADS}'\n")
952 file(APPEND ${CMAKE_BINARY_DIR}/GIT-BUILD-OPTIONS "NO_UNIX_SOCKETS='${NO_UNIX_SOCKETS}'\n")
grep.c
+2 -117
@@ -166,11 +166,6 @@ void grep_init(struct grep_opt *opt, struct repository *repo, const char *prefix
166 pcre2_malloc, pcre2_free, NULL);
167 #endif
168
169 -#ifdef USE_LIBPCRE1
170 - pcre_malloc = malloc;
171 - pcre_free = free;
172 -#endif
173 -
169 *opt = grep_defaults;
170
171 opt->repo = repo;
@@ -223,17 +218,7 @@ static void grep_set_pattern_type_option(enum grep_pattern_type pattern_type, st
218 break;
219
220 case GREP_PATTERN_TYPE_PCRE:
226 -#ifdef USE_LIBPCRE2
221 opt->pcre2 = 1;
228 -#else
229 - /*
230 - * It's important that pcre1 always be assigned to
231 - * even when there's no USE_LIBPCRE* defined. We still
232 - * call the PCRE stub function, it just dies with
233 - * "cannot use Perl-compatible regexes[...]".
234 - */
235 - opt->pcre1 = 1;
236 -#endif
222 break;
223 }
224 }
@@ -377,92 +362,6 @@ static int is_fixed(const char *s, size_t len)
362 return 1;
363 }
364
380 -#ifdef USE_LIBPCRE1
381 -static void compile_pcre1_regexp(struct grep_pat *p, const struct grep_opt *opt)
382 -{
383 - const char *error;
384 - int erroffset;
385 - int options = PCRE_MULTILINE;
386 - int study_options = 0;
387 -
388 - if (opt->ignore_case) {
389 - if (!opt->ignore_locale && has_non_ascii(p->pattern))
390 - p->pcre1_tables = pcre_maketables();
391 - options |= PCRE_CASELESS;
392 - }
393 - if (!opt->ignore_locale && is_utf8_locale() && has_non_ascii(p->pattern))
394 - options |= PCRE_UTF8;
395 -
396 - p->pcre1_regexp = pcre_compile(p->pattern, options, &error, &erroffset,
397 - p->pcre1_tables);
398 - if (!p->pcre1_regexp)
399 - compile_regexp_failed(p, error);
400 -
401 -#if defined(PCRE_CONFIG_JIT) && !defined(NO_LIBPCRE1_JIT)
402 - pcre_config(PCRE_CONFIG_JIT, &p->pcre1_jit_on);
403 - if (opt->debug)
404 - fprintf(stderr, "pcre1_jit_on=%d\n", p->pcre1_jit_on);
405 -
406 - if (p->pcre1_jit_on)
407 - study_options = PCRE_STUDY_JIT_COMPILE;
408 -#endif
409 -
410 - p->pcre1_extra_info = pcre_study(p->pcre1_regexp, study_options, &error);
411 - if (!p->pcre1_extra_info && error)
412 - die("%s", error);
413 -}
414 -
415 -static int pcre1match(struct grep_pat *p, const char *line, const char *eol,
416 - regmatch_t *match, int eflags)
417 -{
418 - int ovector[30], ret, flags = PCRE_NO_UTF8_CHECK;
419 -
420 - if (eflags & REG_NOTBOL)
421 - flags |= PCRE_NOTBOL;
422 -
423 - ret = pcre_exec(p->pcre1_regexp, p->pcre1_extra_info, line,
424 - eol - line, 0, flags, ovector,
425 - ARRAY_SIZE(ovector));
426 -
427 - if (ret < 0 && ret != PCRE_ERROR_NOMATCH)
428 - die("pcre_exec failed with error code %d", ret);
429 - if (ret > 0) {
430 - ret = 0;
431 - match->rm_so = ovector[0];
432 - match->rm_eo = ovector[1];
433 - }
434 -
435 - return ret;
436 -}
437 -
438 -static void free_pcre1_regexp(struct grep_pat *p)
439 -{
440 - pcre_free(p->pcre1_regexp);
441 -#ifdef PCRE_CONFIG_JIT
442 - if (p->pcre1_jit_on)
443 - pcre_free_study(p->pcre1_extra_info);
444 - else
445 -#endif
446 - pcre_free(p->pcre1_extra_info);
447 - pcre_free((void *)p->pcre1_tables);
448 -}
449 -#else /* !USE_LIBPCRE1 */
450 -static void compile_pcre1_regexp(struct grep_pat *p, const struct grep_opt *opt)
451 -{
452 - die("cannot use Perl-compatible regexes when not compiled with USE_LIBPCRE");
453 -}
454 -
455 -static int pcre1match(struct grep_pat *p, const char *line, const char *eol,
456 - regmatch_t *match, int eflags)
457 -{
458 - return 1;
459 -}
460 -
461 -static void free_pcre1_regexp(struct grep_pat *p)
462 -{
463 -}
464 -#endif /* !USE_LIBPCRE1 */
465 -
365 #ifdef USE_LIBPCRE2
366 static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt)
367 {
@@ -588,11 +487,6 @@ static void free_pcre2_pattern(struct grep_pat *p)
487 #else /* !USE_LIBPCRE2 */
488 static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt)
489 {
591 - /*
592 - * Unreachable until USE_LIBPCRE2 becomes synonymous with
593 - * USE_LIBPCRE. See the sibling comment in
594 - * grep_set_pattern_type_option().
595 - */
490 die("cannot use Perl-compatible regexes when not compiled with USE_LIBPCRE");
491 }
492
@@ -693,11 +587,6 @@ static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
587 return;
588 }
589
696 - if (opt->pcre1) {
697 - compile_pcre1_regexp(p, opt);
698 - return;
699 - }
700 -
590 if (p->ignore_case)
591 regflags |= REG_ICASE;
592 if (opt->extended_regexp_option)
@@ -1051,9 +940,7 @@ void free_grep_patterns(struct grep_opt *opt)
940 case GREP_PATTERN: /* atom */
941 case GREP_PATTERN_HEAD:
942 case GREP_PATTERN_BODY:
1054 - if (p->pcre1_regexp)
1055 - free_pcre1_regexp(p);
1056 - else if (p->pcre2_pattern)
943 + if (p->pcre2_pattern)
944 free_pcre2_pattern(p);
945 else
946 regfree(&p->regexp);
@@ -1116,9 +1003,7 @@ static int patmatch(struct grep_pat *p, char *line, char *eol,
1003 {
1004 int hit;
1005
1119 - if (p->pcre1_regexp)
1120 - hit = !pcre1match(p, line, eol, match, eflags);
1121 - else if (p->pcre2_pattern)
1006 + if (p->pcre2_pattern)
1007 hit = !pcre2match(p, line, eol, match, eflags);
1008 else
1009 hit = !regexec_buf(&p->regexp, line, eol - line, 1, match,
grep.h
-14
@@ -1,15 +1,6 @@
1 #ifndef GREP_H
2 #define GREP_H
3 #include "color.h"
4 -#ifdef USE_LIBPCRE1
5 -#include <pcre.h>
6 -#ifndef PCRE_NO_UTF8_CHECK
7 -#define PCRE_NO_UTF8_CHECK 0
8 -#endif
9 -#else
10 -typedef int pcre;
11 -typedef int pcre_extra;
12 -#endif
4 #ifdef USE_LIBPCRE2
5 #define PCRE2_CODE_UNIT_WIDTH 8
6 #include <pcre2.h>
@@ -71,10 +62,6 @@ struct grep_pat {
62 size_t patternlen;
63 enum grep_header_field field;
64 regex_t regexp;
74 - pcre *pcre1_regexp;
75 - pcre_extra *pcre1_extra_info;
76 - const unsigned char *pcre1_tables;
77 - int pcre1_jit_on;
65 pcre2_code *pcre2_pattern;
66 pcre2_match_data *pcre2_match_data;
67 pcre2_compile_context *pcre2_compile_context;
@@ -144,7 +131,6 @@ struct grep_opt {
131 int allow_textconv;
132 int extended;
133 int use_reflog_filter;
147 - int pcre1;
134 int pcre2;
135 int relative;
136 int pathname;
t/README
-12
@@ -1104,18 +1104,6 @@ use these, and "test_set_prereq" for how to define your own.
1104 Git was compiled with support for PCRE. Wrap any tests
1105 that use git-grep --perl-regexp or git-grep -P in these.
1106
1107 - - LIBPCRE1
1108 -
1109 - Git was compiled with PCRE v1 support via
1110 - USE_LIBPCRE1=YesPlease. Wrap any PCRE using tests that for some
1111 - reason need v1 of the PCRE library instead of v2 in these.
1112 -
1113 - - LIBPCRE2
1114 -
1115 - Git was compiled with PCRE v2 support via
1116 - USE_LIBPCRE2=YesPlease. Wrap any PCRE using tests that for some
1117 - reason need v2 of the PCRE library instead of v1 in these.
1118 -
1107 - CASE_INSENSITIVE_FS
1108
1109 Test is run on a case insensitive file system.
t/test-lib.sh
+1 -2
@@ -1524,8 +1524,7 @@ esac
1524 test -z "$NO_PERL" && test_set_prereq PERL
1525 test -z "$NO_PTHREADS" && test_set_prereq PTHREADS
1526 test -z "$NO_PYTHON" && test_set_prereq PYTHON
1527 -test -n "$USE_LIBPCRE1$USE_LIBPCRE2" && test_set_prereq PCRE
1528 -test -n "$USE_LIBPCRE1" && test_set_prereq LIBPCRE1
1527 +test -n "$USE_LIBPCRE2" && test_set_prereq PCRE
1528 test -n "$USE_LIBPCRE2" && test_set_prereq LIBPCRE2
1529 test -z "$NO_GETTEXT" && test_set_prereq GETTEXT
1530