grep/pcre2: use compile-time PCREv2 version test

Replace a use of pcre2_config(PCRE2_CONFIG_VERSION, ...) which I added in 95ca1f987ed (grep/pcre2: better support invalid UTF-8 haystacks, 2021-01-24) with the same test done at compile-time. It might be cuter to do this at runtime since we don't have to do the "major >= 11 || (major >= 10 && ...)" test. But in the next commit we'll add another version comparison that absolutely needs to be done at compile-time, so we're better of being consistent across the board. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Feb 18, 2021 at 01:07 UTC 797c359978eb13ddff10974a6c6469e33695606c
2 files changed +7 -14
grep.c
+4 -14
@@ -400,21 +400,11 @@ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt
400 !(!opt->ignore_case && (p->fixed || p->is_fixed)))
401 options |= (PCRE2_UTF | PCRE2_MATCH_INVALID_UTF);
402
403 +#ifdef GIT_PCRE2_VERSION_10_36_OR_HIGHER
404 /* Work around https://bugs.exim.org/show_bug.cgi?id=2642 fixed in 10.36 */
404 - if (PCRE2_MATCH_INVALID_UTF && options & (PCRE2_UTF | PCRE2_CASELESS)) {
405 - struct strbuf buf;
406 - int len;
407 - int err;
408 -
409 - if ((len = pcre2_config(PCRE2_CONFIG_VERSION, NULL)) < 0)
410 - BUG("pcre2_config(..., NULL) failed: %d", len);
411 - strbuf_init(&buf, len + 1);
412 - if ((err = pcre2_config(PCRE2_CONFIG_VERSION, buf.buf)) < 0)
413 - BUG("pcre2_config(..., buf.buf) failed: %d", err);
414 - if (versioncmp(buf.buf, "10.36") < 0)
415 - options |= PCRE2_NO_START_OPTIMIZE;
416 - strbuf_release(&buf);
417 - }
405 + if (PCRE2_MATCH_INVALID_UTF && options & (PCRE2_UTF | PCRE2_CASELESS))
406 + options |= PCRE2_NO_START_OPTIMIZE;
407 +#endif
408
409 p->pcre2_pattern = pcre2_compile((PCRE2_SPTR)p->pattern,
410 p->patternlen, options, &error, &erroffset,
grep.h
+3
@@ -4,6 +4,9 @@
4 #ifdef USE_LIBPCRE2
5 #define PCRE2_CODE_UNIT_WIDTH 8
6 #include <pcre2.h>
7 +#if (PCRE2_MAJOR >= 10 && PCRE2_MINOR >= 36) || PCRE2_MAJOR >= 11
8 +#define GIT_PCRE2_VERSION_10_36_OR_HIGHER
9 +#endif
10 #else
11 typedef int pcre2_code;
12 typedef int pcre2_match_data;