Skip to content

Commit 797c359

Browse files
avargitster
authored andcommitted
grep/pcre2: use compile-time PCREv2 version test
Replace a use of pcre2_config(PCRE2_CONFIG_VERSION, ...) which I added in 95ca1f9 (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a39b400 commit 797c359

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

grep.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -400,21 +400,11 @@ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt
400400
!(!opt->ignore_case && (p->fixed || p->is_fixed)))
401401
options |= (PCRE2_UTF | PCRE2_MATCH_INVALID_UTF);
402402

403+
#ifdef GIT_PCRE2_VERSION_10_36_OR_HIGHER
403404
/* 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
418408

419409
p->pcre2_pattern = pcre2_compile((PCRE2_SPTR)p->pattern,
420410
p->patternlen, options, &error, &erroffset,

grep.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#ifdef USE_LIBPCRE2
55
#define PCRE2_CODE_UNIT_WIDTH 8
66
#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
710
#else
811
typedef int pcre2_code;
912
typedef int pcre2_match_data;

0 commit comments

Comments
 (0)