{"thread":{"id":"45751","subject":"[PATCH v2 00/13] PCRE v1 improvements & PCRE v2 support","startedAt":"2017-04-19T22:41:23Z","lastAt":"2017-04-19T22:42:14Z","messageCount":14,"participants":["Ævar Arnfjörð Bjarmason"],"isPatch":true,"patchVersion":2,"patchTotal":13},"messages":[{"id":"317276","messageId":"20170419224053.8920-1-avarab@gmail.com","threadId":"45751","inReplyTo":null,"subject":"[PATCH v2 00/13] PCRE v1 improvements & PCRE v2 support","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2017-04-19T22:40:40Z","receivedAt":"2017-04-19T22:41:23Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"It's been a while since I sent v1 of this. I addressed most of the\ncomments, except:\n\n * grep w/submodules doesn't properly pcre2 to submodule greps.\n\n * The critiqued adding runtime complexity by supporting both pcre1 &\n   pcre2 via a switch is still there.\n\nI wanted to get something out the door to review the other bits I've\nchanged sooner than later, so I'm sending it in the state it's in.\nDepending on the consensus for those two issues, fixes for those can\neasily be addedd on top.\n\nComments on specific patches:\n\nÆvar Arnfjörð Bjarmason (13):\n\nFirstly, the \"git grep --threads=N\" patch is missing, that became the\nindependent \"[PATCH v2 0/8] grep threading cleanup & tests\"\nseries. See <20170416222102.2320-1-avarab@gmail.com>.\n\n  grep: remove redundant regflags assignment under PCRE\n\nNo changes.\n\n  Makefile & configure: reword outdated comment about PCRE\n\nFix comment copy as suggested by JK, and explained the confusing\ncopy/pasting of Makefile comments to configure.ac in the commit\nmessage.\n\n  grep: add a test for backreferences in PCRE patterns\n\nNo changes.\n\n  log: add exhaustive tests for pattern style options & config\n\nNow using [\\d] instead of \\((?=1) as a pattern to tell -E and -P\npatterns apart, as suggested by JK.\n\n  log: add -P as a synonym for --perl-regexp\n\nUses the [\\d] pattern now for a test, no other changes.\n\n  grep & rev-list doc: stop promising libpcre for --perl-regexp\n\nNo changes.\n\n  grep: make grep.patternType=[pcre|pcre1] a synonym for \"perl\"\n\nMinor grammar fix in commit message.\n\n  test-lib: rename the LIBPCRE prerequisite to PCRE\n\nNo changes.\n\n  grep: change the internal PCRE macro names to be PCRE1\n\nNo changes.\n\n  grep: change the internal PCRE code & header names to be PCRE1\n\nNo changes.\n\n  perf: add a performance comparison test of grep -E and -P\n\nNEW: Instead of my huge perl -MBenchmark one-liner I wrote a t/perf/\ntest for grep engine comparison which I'm citing for subsequent\nchanges.\n\n  grep: add support for the PCRE v1 JIT API\n\nNEW: Adds JIT support for PCRE v1.\n\n  grep: add support for PCRE v2\n\nLots of changes:\n\n - Much smaller and hopefully less confusing commit message &\n   discussion of performance differences.\n\n - Much improved PCRE v2 API use. The Zoltán Herczeg on the pcre-dev\n   list helped a lot with that. Now less buggy & more performant.\n\n - Plugged a trivial memory leak I missed in v1.\n\nÆvar Arnfjörð Bjarmason (13):\n  grep: remove redundant regflags assignment under PCRE\n  Makefile & configure: reword outdated comment about PCRE\n  grep: add a test for backreferences in PCRE patterns\n  log: add exhaustive tests for pattern style options & config\n  log: add -P as a synonym for --perl-regexp\n  grep & rev-list doc: stop promising libpcre for --perl-regexp\n  grep: make grep.patternType=[pcre|pcre1] a synonym for \"perl\"\n  test-lib: rename the LIBPCRE prerequisite to PCRE\n  grep: change the internal PCRE macro names to be PCRE1\n  grep: change the internal PCRE code & header names to be PCRE1\n  perf: add a performance comparison test of grep -E and -P\n  grep: add support for the PCRE v1 JIT API\n  grep: add support for PCRE v2\n\n Documentation/config.txt           |   7 ++\n Documentation/git-grep.txt         |   4 +-\n Documentation/rev-list-options.txt |   6 +-\n Makefile                           |  28 ++++-\n configure.ac                       |  61 +++++++++-\n grep.c                             | 233 ++++++++++++++++++++++++++++++++-----\n grep.h                             |  36 +++++-\n revision.c                         |   2 +-\n t/README                           |  16 ++-\n t/perf/p7820-grep-engines.sh       |  25 ++++\n t/t4202-log.sh                     |  86 +++++++++++++-\n t/t7810-grep.sh                    |  69 ++++++++---\n t/t7812-grep-icase-non-ascii.sh    |   4 +-\n t/t7813-grep-icase-iso.sh          |  11 +-\n t/test-lib.sh                      |   4 +-\n 15 files changed, 516 insertions(+), 76 deletions(-)\n create mode 100755 t/perf/p7820-grep-engines.sh\n\n-- \n2.11.0\n\n"},{"id":"317277","messageId":"20170419224053.8920-2-avarab@gmail.com","threadId":"45751","inReplyTo":"20170419224053.8920-1-avarab@gmail.com","subject":"[PATCH v2 01/13] grep: remove redundant regflags assignment under PCRE","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2017-04-19T22:40:41Z","receivedAt":"2017-04-19T22:41:24Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Remove a redundant assignment to the \"regflags\" variable. This\nvariable is only used for POSIX regular expression matching, not when\nthe PCRE library is used.\n\nThis redundant assignment was added as a result of copy/paste\nprogramming in commit 84befcd0a4 (\"grep: add a grep.patternType\nconfiguration setting\", 2012-08-03). That commit modified already\nworking code in commit cca2c172e0 (\"git-grep: do not die upon -F/-P\nwhen grep.extendedRegexp is set.\", 2011-05-09) which didn't assign to\nregflags when under PCRE.\n\nRevert back to that behavior, more to reduce \"wait this is used under\nPCRE how?\" confusion when reading the code, than to to save ourselves\ntrivial CPU cycles by removing one assignment.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n grep.c | 1 -\n 1 file changed, 1 deletion(-)\n\ndiff --git a/grep.c b/grep.c\nindex 47cee45067..59ae7809f2 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -197,7 +197,6 @@ static void grep_set_pattern_type_option(enum grep_pattern_type pattern_type, st\n \tcase GREP_PATTERN_TYPE_PCRE:\n \t\topt->fixed = 0;\n \t\topt->pcre = 1;\n-\t\topt->regflags &= ~REG_EXTENDED;\n \t\tbreak;\n \t}\n }\n-- \n2.11.0\n\n"},{"id":"317278","messageId":"20170419224053.8920-3-avarab@gmail.com","threadId":"45751","inReplyTo":"20170419224053.8920-1-avarab@gmail.com","subject":"[PATCH v2 02/13] Makefile & configure: reword outdated comment about PCRE","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2017-04-19T22:40:42Z","receivedAt":"2017-04-19T22:41:34Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Reword an outdated comment which suggests that only git-grep can use\nPCRE.\n\nThis comment was added back when PCRE support was initially added in\ncommit 63e7e9d8b6 (\"git-grep: Learn PCRE\", 2011-05-09), and was true\nat the time.\n\nIt hasn't been telling the full truth since git-log learned to use\nPCRE with --grep in commit 727b6fc3ed (\"log --grep: accept\n--basic-regexp and --perl-regexp\", 2012-10-03), and more importantly\nis likely to get more inaccurate over time as more use is made of PCRE\nin other areas.\n\nReword it to be more future-proof, and to more clearly explain that\nthis enables user-initiated runtime behavior.\n\nCopy/pasting this so much in configure.ac is lame, these Makefile-like\nflags aren't even used by autoconf, just the corresponding\n--with[out]-* options. But copy/pasting the comments that make sense\nfor the Makefile to configure.ac where they make less sence is the\npattern everything else follows in that file. I'm not going to war\nagainst that as part of this change, just following the existing\npattern.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n Makefile     |  6 ++++--\n configure.ac | 12 ++++++++----\n 2 files changed, 12 insertions(+), 6 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex d595ea3837..516f57aac8 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -24,8 +24,10 @@ all::\n # Define NO_OPENSSL environment variable if you do not have OpenSSL.\n # This also implies BLK_SHA1.\n #\n-# Define USE_LIBPCRE if you have and want to use libpcre. git-grep will be\n-# able to use Perl-compatible regular expressions.\n+# Define USE_LIBPCRE if you have and want to use libpcre. Various\n+# commands such as log and grep offer runtime options to use\n+# Perl-compatible regular expressions instead of standard or extended\n+# POSIX regular expressions.\n #\n # Define LIBPCREDIR=/foo/bar if your libpcre header and library files are in\n # /foo/bar/include and /foo/bar/lib directories.\ndiff --git a/configure.ac b/configure.ac\nindex 128165529f..deeb968daa 100644\n--- a/configure.ac\n+++ b/configure.ac\n@@ -250,8 +250,10 @@ AS_HELP_STRING([--with-openssl],[use OpenSSL library (default is YES)])\n AS_HELP_STRING([],              [ARG can be prefix for openssl library and headers]),\n GIT_PARSE_WITH([openssl]))\n \n-# Define USE_LIBPCRE if you have and want to use libpcre. git-grep will be\n-# able to use Perl-compatible regular expressions.\n+# Define USE_LIBPCRE if you have and want to use libpcre. Various\n+# commands such as log and grep offer runtime options to use\n+# Perl-compatible regular expressions instead of standard or extended\n+# POSIX regular expressions.\n #\n # Define LIBPCREDIR=/foo/bar if your libpcre header and library files are in\n # /foo/bar/include and /foo/bar/lib directories.\n@@ -499,8 +501,10 @@ GIT_CONF_SUBST([NEEDS_SSL_WITH_CRYPTO])\n GIT_CONF_SUBST([NO_OPENSSL])\n \n #\n-# Define USE_LIBPCRE if you have and want to use libpcre. git-grep will be\n-# able to use Perl-compatible regular expressions.\n+# Define USE_LIBPCRE if you have and want to use libpcre. Various\n+# commands such as log and grep offer runtime options to use\n+# Perl-compatible regular expressions instead of standard or extended\n+# POSIX regular expressions.\n #\n \n if test -n \"$USE_LIBPCRE\"; then\n-- \n2.11.0\n\n"},{"id":"317279","messageId":"20170419224053.8920-4-avarab@gmail.com","threadId":"45751","inReplyTo":"20170419224053.8920-1-avarab@gmail.com","subject":"[PATCH v2 03/13] grep: add a test for backreferences in PCRE patterns","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2017-04-19T22:40:43Z","receivedAt":"2017-04-19T22:41:36Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Add a test for backreferences such as (.)\\1 in PCRE patterns. This\ntest ensures that the PCRE_NO_AUTO_CAPTURE option isn't turned\non. Before this change turning it on would break these sort of\npatterns, but wouldn't break any tests.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n t/t7810-grep.sh | 7 +++++++\n 1 file changed, 7 insertions(+)\n\ndiff --git a/t/t7810-grep.sh b/t/t7810-grep.sh\nindex cee42097b0..8baed0f37d 100755\n--- a/t/t7810-grep.sh\n+++ b/t/t7810-grep.sh\n@@ -1102,6 +1102,13 @@ test_expect_success LIBPCRE 'grep -P -w pattern' '\n \ttest_cmp expected actual\n '\n \n+test_expect_success PCRE 'grep -P backreferences work (the PCRE NO_AUTO_CAPTURE flag is not set)' '\n+\tgit grep -P -h \"(?P<one>.)(?P=one)\" hello_world >actual &&\n+\ttest_cmp hello_world actual &&\n+\tgit grep -P -h \"(.)\\1\" hello_world >actual &&\n+\ttest_cmp hello_world actual\n+'\n+\n test_expect_success 'grep -G invalidpattern properly dies ' '\n \ttest_must_fail git grep -G \"a[\"\n '\n-- \n2.11.0\n\n"},{"id":"317280","messageId":"20170419224053.8920-5-avarab@gmail.com","threadId":"45751","inReplyTo":"20170419224053.8920-1-avarab@gmail.com","subject":"[PATCH v2 04/13] log: add exhaustive tests for pattern style options & config","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2017-04-19T22:40:44Z","receivedAt":"2017-04-19T22:41:37Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Add exhaustive tests for how the different grep.patternType options &\nthe corresponding command-line options affect git-log.\n\nBefore this change it was possible to patch revision.c so that the\n--basic-regexp option was synonymous with --extended-regexp, and\n--perl-regexp wasn't recognized at all, and still have 100% of the\ntest suite pass.\n\nThis was because the first test being modified here, added in commit\n34a4ae55b2 (\"log --grep: use the same helper to set -E/-F options as\n\"git grep\"\", 2012-10-03), didn't actually check whether we'd enabled\nextended regular expressions as distinct from re-toggling non-fixed\nstring support.\n\nFix that by changing the pattern to a pattern that'll only match if\n--extended-regexp option is provided, but won't match under the\ndefault --basic-regexp option.\n\nOther potential regressions were possible since there were no tests\nfor the rest of the combinations of grep.patternType configuration\ntoggles & corresponding git-log command-line options. Add exhaustive\ntests for those.\n\nThe patterns being passed to fixed/basic/extended/PCRE are carefully\ncrafted to return the wrong thing if the grep engine were to pick any\nother matching method than the one it's told to use.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n t/t4202-log.sh | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-\n 1 file changed, 76 insertions(+), 1 deletion(-)\n\ndiff --git a/t/t4202-log.sh b/t/t4202-log.sh\nindex f577990716..fc186f10ea 100755\n--- a/t/t4202-log.sh\n+++ b/t/t4202-log.sh\n@@ -262,7 +262,23 @@ test_expect_success 'log --grep -i' '\n \n test_expect_success 'log -F -E --grep=<ere> uses ere' '\n \techo second >expect &&\n-\tgit log -1 --pretty=\"tformat:%s\" -F -E --grep=s.c.nd >actual &&\n+\tgit log -1 --pretty=\"tformat:%s\" -F -E --grep=\"(s).c.nd\" >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success LIBPCRE 'log -F -E --perl-regexp --grep=<pcre> uses PCRE' '\n+\ttest_when_finished \"rm -rf num_commits\" &&\n+\tgit init num_commits &&\n+\t(\n+\t\tcd num_commits &&\n+\t\ttest_commit 1d &&\n+\t\ttest_commit 2e\n+\t) &&\n+\techo 2e >expect &&\n+\tgit -C num_commits log -1 --pretty=\"tformat:%s\" -F -E --perl-regexp --grep=\"[\\d]\" >actual &&\n+\ttest_cmp expect actual &&\n+\techo 1d >expect &&\n+\tgit -C num_commits log -1 --pretty=\"tformat:%s\" -F -E --grep=\"[\\d]\" >actual &&\n \ttest_cmp expect actual\n '\n \n@@ -280,6 +296,65 @@ test_expect_success 'log with grep.patternType configuration and command line' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success 'log with various grep.patternType configurations & command-lines' '\n+\tgit init pattern-type &&\n+\t(\n+\t\tcd pattern-type &&\n+\t\ttest_commit 1 file A &&\n+\t\ttest_commit \"(1|2)\" file B &&\n+\n+\t\techo \"(1|2)\" >expect.fixed &&\n+\t\tcp expect.fixed expect.basic &&\n+\t\tcp expect.fixed expect.extended &&\n+\t\tcp expect.fixed expect.perl &&\n+\n+\t\tgit -c grep.patternType=fixed log --pretty=tformat:%s \\\n+\t\t\t--grep=\"(1|2)\" >actual.fixed &&\n+\t\tgit -c grep.patternType=basic log --pretty=tformat:%s \\\n+\t\t\t--grep=\"(.|.)\" >actual.basic &&\n+\t\tgit -c grep.patternType=extended log --pretty=tformat:%s \\\n+\t\t\t--grep=\"\\|2\" >actual.extended &&\n+\t\tif test_have_prereq LIBPCRE\n+\t\tthen\n+\t\t\tgit -c grep.patternType=perl log --pretty=tformat:%s \\\n+\t\t\t\t--grep=\"[\\d]\\|\" >actual.perl\n+\t\tfi &&\n+\t\ttest_cmp expect.fixed actual.fixed &&\n+\t\ttest_cmp expect.basic actual.basic &&\n+\t\ttest_cmp expect.extended actual.extended &&\n+\t\tif test_have_prereq LIBPCRE\n+\t\tthen\n+\t\t\ttest_cmp expect.perl actual.perl\n+\t\tfi &&\n+\n+\t\tgit log --pretty=tformat:%s -F \\\n+\t\t\t--grep=\"(1|2)\" >actual.fixed.short-arg &&\n+\t\tgit log --pretty=tformat:%s -E \\\n+\t\t\t--grep=\"\\|2\" >actual.extended.short-arg &&\n+\t\ttest_cmp expect.fixed actual.fixed.short-arg &&\n+\t\ttest_cmp expect.extended actual.extended.short-arg &&\n+\n+\t\tgit log --pretty=tformat:%s --fixed-strings \\\n+\t\t\t--grep=\"(1|2)\" >actual.fixed.long-arg &&\n+\t\tgit log --pretty=tformat:%s --basic-regexp \\\n+\t\t\t--grep=\"(.|.)\" >actual.basic.long-arg &&\n+\t\tgit log --pretty=tformat:%s --extended-regexp \\\n+\t\t\t--grep=\"\\|2\" >actual.extended.long-arg &&\n+\t\tif test_have_prereq LIBPCRE\n+\t\tthen\n+\t\t\tgit log --pretty=tformat:%s --perl-regexp \\\n+\t\t\t\t--grep=\"[\\d]\\|\" >actual.perl.long-arg\n+\t\tfi &&\n+\t\ttest_cmp expect.fixed actual.fixed.long-arg &&\n+\t\ttest_cmp expect.basic actual.basic.long-arg &&\n+\t\ttest_cmp expect.extended actual.extended.long-arg &&\n+\t\tif test_have_prereq LIBPCRE\n+\t\tthen\n+\t\t\ttest_cmp expect.perl actual.perl.long-arg\n+\t\tfi\n+\t)\n+'\n+\n cat > expect <<EOF\n * Second\n * sixth\n-- \n2.11.0\n\n"},{"id":"317281","messageId":"20170419224053.8920-6-avarab@gmail.com","threadId":"45751","inReplyTo":"20170419224053.8920-1-avarab@gmail.com","subject":"[PATCH v2 05/13] log: add -P as a synonym for --perl-regexp","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2017-04-19T22:40:45Z","receivedAt":"2017-04-19T22:41:41Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Add a short -P option as a synonym for the longer --perl-regexp, for\nconsistency with the options the corresponding grep invocations\naccept.\n\nThis was intentionally omitted in commit 727b6fc3ed (\"log --grep:\naccept --basic-regexp and --perl-regexp\", 2012-10-03) for unspecified\nfuture use.\n\nSince nothing has come along in over 4 1/2 years that's wanted to use\nit, it's more valuable to make it consistent with \"grep\" than to keep\nit open for future use, and to avoid the confusion of -P meaning\ndifferent things for grep & log, as is the case with the -G option.\n\nAs noted in the aforementioned commit the --basic-regexp option can't\nhave a corresponding -G argument, as the log command already uses that\nfor -G<regex>.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n Documentation/rev-list-options.txt | 1 +\n revision.c                         | 2 +-\n t/t4202-log.sh                     | 9 +++++++++\n 3 files changed, 11 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt\nindex a02f7324c0..5b7fa49a7f 100644\n--- a/Documentation/rev-list-options.txt\n+++ b/Documentation/rev-list-options.txt\n@@ -91,6 +91,7 @@ endif::git-rev-list[]\n \tConsider the limiting patterns to be fixed strings (don't interpret\n \tpattern as a regular expression).\n \n+-P::\n --perl-regexp::\n \tConsider the limiting patterns to be Perl-compatible regular expressions.\n \tRequires libpcre to be compiled in.\ndiff --git a/revision.c b/revision.c\nindex 7ff61ff5f7..03a3a012de 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -1995,7 +1995,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg\n \t\tDIFF_OPT_SET(&revs->diffopt, PICKAXE_IGNORE_CASE);\n \t} else if (!strcmp(arg, \"--fixed-strings\") || !strcmp(arg, \"-F\")) {\n \t\trevs->grep_filter.pattern_type_option = GREP_PATTERN_TYPE_FIXED;\n-\t} else if (!strcmp(arg, \"--perl-regexp\")) {\n+\t} else if (!strcmp(arg, \"--perl-regexp\") || !strcmp(arg, \"-P\")) {\n \t\trevs->grep_filter.pattern_type_option = GREP_PATTERN_TYPE_PCRE;\n \t} else if (!strcmp(arg, \"--all-match\")) {\n \t\trevs->grep_filter.all_match = 1;\ndiff --git a/t/t4202-log.sh b/t/t4202-log.sh\nindex fc186f10ea..06acc848b8 100755\n--- a/t/t4202-log.sh\n+++ b/t/t4202-log.sh\n@@ -331,8 +331,17 @@ test_expect_success 'log with various grep.patternType configurations & command-\n \t\t\t--grep=\"(1|2)\" >actual.fixed.short-arg &&\n \t\tgit log --pretty=tformat:%s -E \\\n \t\t\t--grep=\"\\|2\" >actual.extended.short-arg &&\n+\t\tif test_have_prereq PCRE\n+\t\tthen\n+\t\t\tgit log --pretty=tformat:%s -P \\\n+\t\t\t\t--grep=\"[\\d]\\|\" >actual.perl.short-arg\n+\t\tfi &&\n \t\ttest_cmp expect.fixed actual.fixed.short-arg &&\n \t\ttest_cmp expect.extended actual.extended.short-arg &&\n+\t\tif test_have_prereq PCRE\n+\t\tthen\n+\t\t\ttest_cmp expect.perl actual.perl.short-arg\n+\t\tfi &&\n \n \t\tgit log --pretty=tformat:%s --fixed-strings \\\n \t\t\t--grep=\"(1|2)\" >actual.fixed.long-arg &&\n-- \n2.11.0\n\n"},{"id":"317282","messageId":"20170419224053.8920-7-avarab@gmail.com","threadId":"45751","inReplyTo":"20170419224053.8920-1-avarab@gmail.com","subject":"[PATCH v2 06/13] grep & rev-list doc: stop promising libpcre for --perl-regexp","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2017-04-19T22:40:46Z","receivedAt":"2017-04-19T22:41:44Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Stop promising in our grep & rev-list options documentation that we're\nalways going to be using libpcre when given the --perl-regexp option.\n\nInstead talk about using \"Perl-compatible regular expressions\" and\nusing \"the PCRE library\". Saying \"libpcre\" strongly suggests that we\nmight be talking about libpcre.so, which is always going to be v1.\n\nNot only do does the documentation now align more clearly with future\nplans, but it should be more easily readable to the layman.\n\nThis is for preparation for libpcre2 support, which in the future may\nbe powering the --perl-regexp option by default, depending on how Git\nis compiled.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n Documentation/git-grep.txt         | 4 ++--\n Documentation/rev-list-options.txt | 5 +++--\n 2 files changed, 5 insertions(+), 4 deletions(-)\n\ndiff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt\nindex 71f32f3508..e42ba83c42 100644\n--- a/Documentation/git-grep.txt\n+++ b/Documentation/git-grep.txt\n@@ -161,8 +161,8 @@ OPTIONS\n \n -P::\n --perl-regexp::\n-\tUse Perl-compatible regexp for patterns. Requires libpcre to be\n-\tcompiled in.\n+\tUse Perl-compatible regular expressions for patterns. Uses the\n+\tPCRE library, which Git needs to be compiled against.\n \n -F::\n --fixed-strings::\ndiff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt\nindex 5b7fa49a7f..565cde636e 100644\n--- a/Documentation/rev-list-options.txt\n+++ b/Documentation/rev-list-options.txt\n@@ -93,8 +93,9 @@ endif::git-rev-list[]\n \n -P::\n --perl-regexp::\n-\tConsider the limiting patterns to be Perl-compatible regular expressions.\n-\tRequires libpcre to be compiled in.\n+\tConsider the limiting patterns to be Perl-compatible regular\n+\texpressions. Uses the PCRE library, which Git needs to be\n+\tcompiled against.\n \n --remove-empty::\n \tStop when a given path disappears from the tree.\n-- \n2.11.0\n\n"},{"id":"317283","messageId":"20170419224053.8920-9-avarab@gmail.com","threadId":"45751","inReplyTo":"20170419224053.8920-1-avarab@gmail.com","subject":"[PATCH v2 08/13] test-lib: rename the LIBPCRE prerequisite to PCRE","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2017-04-19T22:40:48Z","receivedAt":"2017-04-19T22:41:50Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Rename the LIBPCRE prerequisite to PCRE. This is for preparation for\nlibpcre2 support, where having just \"LIBPCRE\" would be confusing as it\nimplies v1 of the library.\n\nNone of these tests are incompatible between versions 1 & 2 of\nlibpcre, it's less confusing to give them a more general name to make\nit clear that they work on both library versions.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n t/README                        |  4 ++--\n t/t4202-log.sh                  | 10 +++++-----\n t/t7810-grep.sh                 | 30 +++++++++++++++---------------\n t/t7812-grep-icase-non-ascii.sh |  4 ++--\n t/t7813-grep-icase-iso.sh       |  2 +-\n t/test-lib.sh                   |  2 +-\n 6 files changed, 26 insertions(+), 26 deletions(-)\n\ndiff --git a/t/README b/t/README\nindex ab386c3681..a90cb62583 100644\n--- a/t/README\n+++ b/t/README\n@@ -803,9 +803,9 @@ use these, and \"test_set_prereq\" for how to define your own.\n    Test is not run by root user, and an attempt to write to an\n    unwritable file is expected to fail correctly.\n \n- - LIBPCRE\n+ - PCRE\n \n-   Git was compiled with USE_LIBPCRE=YesPlease. Wrap any tests\n+   Git was compiled with support for PCRE. Wrap any tests\n    that use git-grep --perl-regexp or git-grep -P in these.\n \n  - CASE_INSENSITIVE_FS\ndiff --git a/t/t4202-log.sh b/t/t4202-log.sh\nindex 06acc848b8..0b5f808ca3 100755\n--- a/t/t4202-log.sh\n+++ b/t/t4202-log.sh\n@@ -266,7 +266,7 @@ test_expect_success 'log -F -E --grep=<ere> uses ere' '\n \ttest_cmp expect actual\n '\n \n-test_expect_success LIBPCRE 'log -F -E --perl-regexp --grep=<pcre> uses PCRE' '\n+test_expect_success PCRE 'log -F -E --perl-regexp --grep=<pcre> uses PCRE' '\n \ttest_when_finished \"rm -rf num_commits\" &&\n \tgit init num_commits &&\n \t(\n@@ -314,7 +314,7 @@ test_expect_success 'log with various grep.patternType configurations & command-\n \t\t\t--grep=\"(.|.)\" >actual.basic &&\n \t\tgit -c grep.patternType=extended log --pretty=tformat:%s \\\n \t\t\t--grep=\"\\|2\" >actual.extended &&\n-\t\tif test_have_prereq LIBPCRE\n+\t\tif test_have_prereq PCRE\n \t\tthen\n \t\t\tgit -c grep.patternType=perl log --pretty=tformat:%s \\\n \t\t\t\t--grep=\"[\\d]\\|\" >actual.perl\n@@ -322,7 +322,7 @@ test_expect_success 'log with various grep.patternType configurations & command-\n \t\ttest_cmp expect.fixed actual.fixed &&\n \t\ttest_cmp expect.basic actual.basic &&\n \t\ttest_cmp expect.extended actual.extended &&\n-\t\tif test_have_prereq LIBPCRE\n+\t\tif test_have_prereq PCRE\n \t\tthen\n \t\t\ttest_cmp expect.perl actual.perl\n \t\tfi &&\n@@ -349,7 +349,7 @@ test_expect_success 'log with various grep.patternType configurations & command-\n \t\t\t--grep=\"(.|.)\" >actual.basic.long-arg &&\n \t\tgit log --pretty=tformat:%s --extended-regexp \\\n \t\t\t--grep=\"\\|2\" >actual.extended.long-arg &&\n-\t\tif test_have_prereq LIBPCRE\n+\t\tif test_have_prereq PCRE\n \t\tthen\n \t\t\tgit log --pretty=tformat:%s --perl-regexp \\\n \t\t\t\t--grep=\"[\\d]\\|\" >actual.perl.long-arg\n@@ -357,7 +357,7 @@ test_expect_success 'log with various grep.patternType configurations & command-\n \t\ttest_cmp expect.fixed actual.fixed.long-arg &&\n \t\ttest_cmp expect.basic actual.basic.long-arg &&\n \t\ttest_cmp expect.extended actual.extended.long-arg &&\n-\t\tif test_have_prereq LIBPCRE\n+\t\tif test_have_prereq PCRE\n \t\tthen\n \t\t\ttest_cmp expect.perl actual.perl.long-arg\n \t\tfi\ndiff --git a/t/t7810-grep.sh b/t/t7810-grep.sh\nindex 0fb95c7438..f929b447e9 100755\n--- a/t/t7810-grep.sh\n+++ b/t/t7810-grep.sh\n@@ -275,7 +275,7 @@ do\n \t\ttest_cmp expected actual\n \t'\n \n-\ttest_expect_success LIBPCRE \"grep $L with grep.patterntype=perl\" '\n+\ttest_expect_success PCRE \"grep $L with grep.patterntype=perl\" '\n \t\techo \"${HC}ab:a+b*c\" >expected &&\n \t\tgit -c grep.patterntype=perl grep \"a\\x{2b}b\\x{2a}c\" $H ab >actual &&\n \t\ttest_cmp expected actual\n@@ -1053,12 +1053,12 @@ hello.c:int main(int argc, const char **argv)\n hello.c:\tprintf(\"Hello world.\\n\");\n EOF\n \n-test_expect_success LIBPCRE 'grep --perl-regexp pattern' '\n+test_expect_success PCRE 'grep --perl-regexp pattern' '\n \tgit grep --perl-regexp \"\\p{Ps}.*?\\p{Pe}\" hello.c >actual &&\n \ttest_cmp expected actual\n '\n \n-test_expect_success LIBPCRE 'grep -P pattern' '\n+test_expect_success PCRE 'grep -P pattern' '\n \tgit grep -P \"\\p{Ps}.*?\\p{Pe}\" hello.c >actual &&\n \ttest_cmp expected actual\n '\n@@ -1070,13 +1070,13 @@ test_expect_success 'grep pattern with grep.extendedRegexp=true' '\n \ttest_cmp empty actual\n '\n \n-test_expect_success LIBPCRE 'grep -P pattern with grep.extendedRegexp=true' '\n+test_expect_success PCRE 'grep -P pattern with grep.extendedRegexp=true' '\n \tgit -c grep.extendedregexp=true \\\n \t\tgrep -P \"\\p{Ps}.*?\\p{Pe}\" hello.c >actual &&\n \ttest_cmp expected actual\n '\n \n-test_expect_success LIBPCRE 'grep -P -v pattern' '\n+test_expect_success PCRE 'grep -P -v pattern' '\n \t{\n \t\techo \"ab:a+b*c\"\n \t\techo \"ab:a+bc\"\n@@ -1085,7 +1085,7 @@ test_expect_success LIBPCRE 'grep -P -v pattern' '\n \ttest_cmp expected actual\n '\n \n-test_expect_success LIBPCRE 'grep -P -i pattern' '\n+test_expect_success PCRE 'grep -P -i pattern' '\n \tcat >expected <<-EOF &&\n \thello.c:\tprintf(\"Hello world.\\n\");\n \tEOF\n@@ -1093,7 +1093,7 @@ test_expect_success LIBPCRE 'grep -P -i pattern' '\n \ttest_cmp expected actual\n '\n \n-test_expect_success LIBPCRE 'grep -P -w pattern' '\n+test_expect_success PCRE 'grep -P -w pattern' '\n \t{\n \t\techo \"hello_world:Hello world\"\n \t\techo \"hello_world:HeLLo world\"\n@@ -1125,11 +1125,11 @@ test_expect_success 'grep invalidpattern properly dies with grep.patternType=ext\n \ttest_must_fail git -c grep.patterntype=extended grep \"a[\"\n '\n \n-test_expect_success LIBPCRE 'grep -P invalidpattern properly dies ' '\n+test_expect_success PCRE 'grep -P invalidpattern properly dies ' '\n \ttest_must_fail git grep -P \"a[\"\n '\n \n-test_expect_success LIBPCRE 'grep invalidpattern properly dies with grep.patternType=perl' '\n+test_expect_success PCRE 'grep invalidpattern properly dies with grep.patternType=perl' '\n \ttest_must_fail git -c grep.patterntype=perl grep \"a[\"\n '\n \n@@ -1198,13 +1198,13 @@ test_expect_success 'grep pattern with grep.patternType=fixed, =basic, =perl, =e\n \ttest_cmp expected actual\n '\n \n-test_expect_success LIBPCRE 'grep -G -F -E -P pattern' '\n+test_expect_success PCRE 'grep -G -F -E -P pattern' '\n \techo \"d0:0\" >expected &&\n \tgit grep -G -F -E -P \"[\\d]\" d0 >actual &&\n \ttest_cmp expected actual\n '\n \n-test_expect_success LIBPCRE 'grep pattern with grep.patternType=fixed, =basic, =extended, =perl' '\n+test_expect_success PCRE 'grep pattern with grep.patternType=fixed, =basic, =extended, =perl' '\n \techo \"d0:0\" >expected &&\n \tgit \\\n \t\t-c grep.patterntype=fixed \\\n@@ -1215,7 +1215,7 @@ test_expect_success LIBPCRE 'grep pattern with grep.patternType=fixed, =basic, =\n \ttest_cmp expected actual\n '\n \n-test_expect_success LIBPCRE 'grep -P pattern with grep.patternType=fixed' '\n+test_expect_success PCRE 'grep -P pattern with grep.patternType=fixed' '\n \techo \"ab:a+b*c\" >expected &&\n \tgit \\\n \t\t-c grep.patterntype=fixed \\\n@@ -1350,12 +1350,12 @@ space: line with leading space2\n space: line with leading space3\n EOF\n \n-test_expect_success LIBPCRE 'grep -E \"^ \"' '\n+test_expect_success PCRE 'grep -E \"^ \"' '\n \tgit grep -E \"^ \" space >actual &&\n \ttest_cmp expected actual\n '\n \n-test_expect_success LIBPCRE 'grep -P \"^ \"' '\n+test_expect_success PCRE 'grep -P \"^ \"' '\n \tgit grep -P \"^ \" space >actual &&\n \ttest_cmp expected actual\n '\n@@ -1512,7 +1512,7 @@ test_expect_success 'grep does not report i-t-a and assume unchanged with -L' '\n \ttest_cmp expected actual\n '\n \n-test_expect_success LIBPCRE \"grep with grep.patternType synonyms perl/pcre/pcre1\" '\n+test_expect_success PCRE \"grep with grep.patternType synonyms perl/pcre/pcre1\" '\n \techo \"#include <stdio.h>\" >expected &&\n \tgit -c grep.patternType=perl  grep -h --no-line-number \"st(?=dio)\" >actual &&\n \ttest_cmp expected actual &&\ndiff --git a/t/t7812-grep-icase-non-ascii.sh b/t/t7812-grep-icase-non-ascii.sh\nindex 169fd8d706..04a61cb8e0 100755\n--- a/t/t7812-grep-icase-non-ascii.sh\n+++ b/t/t7812-grep-icase-non-ascii.sh\n@@ -20,13 +20,13 @@ test_expect_success REGEX_LOCALE 'grep literal string, no -F' '\n \tgit grep -i \"TILRAUN: HALLÓ HEIMUR!\"\n '\n \n-test_expect_success GETTEXT_LOCALE,LIBPCRE 'grep pcre utf-8 icase' '\n+test_expect_success GETTEXT_LOCALE,PCRE 'grep pcre utf-8 icase' '\n \tgit grep --perl-regexp    \"TILRAUN: H.lló Heimur!\" &&\n \tgit grep --perl-regexp -i \"TILRAUN: H.lló Heimur!\" &&\n \tgit grep --perl-regexp -i \"TILRAUN: H.LLÓ HEIMUR!\"\n '\n \n-test_expect_success GETTEXT_LOCALE,LIBPCRE 'grep pcre utf-8 string with \"+\"' '\n+test_expect_success GETTEXT_LOCALE,PCRE 'grep pcre utf-8 string with \"+\"' '\n \ttest_write_lines \"TILRAUN: Hallóó Heimur!\" >file2 &&\n \tgit add file2 &&\n \tgit grep -l --perl-regexp \"TILRAUN: H.lló+ Heimur!\" >actual &&\ndiff --git a/t/t7813-grep-icase-iso.sh b/t/t7813-grep-icase-iso.sh\nindex efef7fb81f..701e08a8e5 100755\n--- a/t/t7813-grep-icase-iso.sh\n+++ b/t/t7813-grep-icase-iso.sh\n@@ -11,7 +11,7 @@ test_expect_success GETTEXT_ISO_LOCALE 'setup' '\n \texport LC_ALL\n '\n \n-test_expect_success GETTEXT_ISO_LOCALE,LIBPCRE 'grep pcre string' '\n+test_expect_success GETTEXT_ISO_LOCALE,PCRE 'grep pcre string' '\n \tgit grep --perl-regexp -i \"TILRAUN: H.ll� Heimur!\" &&\n \tgit grep --perl-regexp -i \"TILRAUN: H.LL� HEIMUR!\"\n '\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex 13b5696822..6abf1d1918 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -1010,7 +1010,7 @@ esac\n ( COLUMNS=1 && test $COLUMNS = 1 ) && test_set_prereq COLUMNS_CAN_BE_1\n test -z \"$NO_PERL\" && test_set_prereq PERL\n test -z \"$NO_PYTHON\" && test_set_prereq PYTHON\n-test -n \"$USE_LIBPCRE\" && test_set_prereq LIBPCRE\n+test -n \"$USE_LIBPCRE\" && test_set_prereq PCRE\n test -z \"$NO_GETTEXT\" && test_set_prereq GETTEXT\n \n # Can we rely on git's output in the C locale?\n-- \n2.11.0\n\n"},{"id":"317284","messageId":"20170419224053.8920-10-avarab@gmail.com","threadId":"45751","inReplyTo":"20170419224053.8920-1-avarab@gmail.com","subject":"[PATCH v2 09/13] grep: change the internal PCRE macro names to be PCRE1","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2017-04-19T22:40:49Z","receivedAt":"2017-04-19T22:41:54Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Change the internal USE_LIBPCRE define, & build options flag to use a\nnaming convention ending in PCRE1, without changing the long-standing\nUSE_LIBPCRE Makefile flag which enables this code.\n\nThis is for preparation for libpcre2 support where having things like\nUSE_LIBPCRE and USE_LIBPCRE2 in any more places than we absolutely\nneed to for backwards compatibility with old Makefile arguments would\nbe confusing.\n\nIn some ways it would be better to change everything that now uses\nUSE_LIBPCRE to use USE_LIBPCRE1, and to make specifying\nUSE_LIBPCRE (or --with-pcre) an error. This would impose a one-time\nburden on packagers of git to s/USE_LIBPCRE/USE_LIBPCRE1/ in their\nbuild scripts.\n\nHowever I'd like to leave the door open to making\nUSE_LIBPCRE=YesPlease eventually mean USE_LIBPCRE2=YesPlease,\ni.e. once PCRE v2 is ubiquitous enough that it makes sense to make it\nthe default.\n\nThis code and the USE_LIBPCRE Makefile argument was added in commit\n63e7e9d8b6 (\"git-grep: Learn PCRE\", 2011-05-09). At the time there was\nno indication that the PCRE project would release an entirely new &\nincompatible API around 3 years later.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n Makefile      | 4 ++--\n grep.c        | 6 +++---\n grep.h        | 2 +-\n t/test-lib.sh | 2 +-\n 4 files changed, 7 insertions(+), 7 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 516f57aac8..cd19980906 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1084,7 +1084,7 @@ ifdef NO_LIBGEN_H\n endif\n \n ifdef USE_LIBPCRE\n-\tBASIC_CFLAGS += -DUSE_LIBPCRE\n+\tBASIC_CFLAGS += -DUSE_LIBPCRE1\n \tifdef LIBPCREDIR\n \t\tBASIC_CFLAGS += -I$(LIBPCREDIR)/include\n \t\tEXTLIBS += -L$(LIBPCREDIR)/$(lib) $(CC_LD_DYNPATH)$(LIBPCREDIR)/$(lib)\n@@ -2236,7 +2236,7 @@ GIT-BUILD-OPTIONS: FORCE\n \t@echo TAR=\\''$(subst ','\\'',$(subst ','\\'',$(TAR)))'\\' >>$@+\n \t@echo NO_CURL=\\''$(subst ','\\'',$(subst ','\\'',$(NO_CURL)))'\\' >>$@+\n \t@echo NO_EXPAT=\\''$(subst ','\\'',$(subst ','\\'',$(NO_EXPAT)))'\\' >>$@+\n-\t@echo USE_LIBPCRE=\\''$(subst ','\\'',$(subst ','\\'',$(USE_LIBPCRE)))'\\' >>$@+\n+\t@echo USE_LIBPCRE1=\\''$(subst ','\\'',$(subst ','\\'',$(USE_LIBPCRE)))'\\' >>$@+\n \t@echo NO_PERL=\\''$(subst ','\\'',$(subst ','\\'',$(NO_PERL)))'\\' >>$@+\n \t@echo NO_PYTHON=\\''$(subst ','\\'',$(subst ','\\'',$(NO_PYTHON)))'\\' >>$@+\n \t@echo NO_UNIX_SOCKETS=\\''$(subst ','\\'',$(subst ','\\'',$(NO_UNIX_SOCKETS)))'\\' >>$@+\ndiff --git a/grep.c b/grep.c\nindex 506545c0ee..2535abd214 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -325,7 +325,7 @@ static NORETURN void compile_regexp_failed(const struct grep_pat *p,\n \tdie(\"%s'%s': %s\", where, p->pattern, error);\n }\n \n-#ifdef USE_LIBPCRE\n+#ifdef USE_LIBPCRE1\n static void compile_pcre_regexp(struct grep_pat *p, const struct grep_opt *opt)\n {\n \tconst char *error;\n@@ -377,7 +377,7 @@ static void free_pcre_regexp(struct grep_pat *p)\n \tpcre_free(p->pcre_extra_info);\n \tpcre_free((void *)p->pcre_tables);\n }\n-#else /* !USE_LIBPCRE */\n+#else /* !USE_LIBPCRE1 */\n static void compile_pcre_regexp(struct grep_pat *p, const struct grep_opt *opt)\n {\n \tdie(\"cannot use Perl-compatible regexes when not compiled with USE_LIBPCRE\");\n@@ -392,7 +392,7 @@ static int pcrematch(struct grep_pat *p, const char *line, const char *eol,\n static void free_pcre_regexp(struct grep_pat *p)\n {\n }\n-#endif /* !USE_LIBPCRE */\n+#endif /* !USE_LIBPCRE1 */\n \n static int is_fixed(const char *s, size_t len)\n {\ndiff --git a/grep.h b/grep.h\nindex 267534ca24..073b0e4c92 100644\n--- a/grep.h\n+++ b/grep.h\n@@ -1,7 +1,7 @@\n #ifndef GREP_H\n #define GREP_H\n #include \"color.h\"\n-#ifdef USE_LIBPCRE\n+#ifdef USE_LIBPCRE1\n #include <pcre.h>\n #else\n typedef int pcre;\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex 6abf1d1918..e5cfbcc36b 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -1010,7 +1010,7 @@ esac\n ( COLUMNS=1 && test $COLUMNS = 1 ) && test_set_prereq COLUMNS_CAN_BE_1\n test -z \"$NO_PERL\" && test_set_prereq PERL\n test -z \"$NO_PYTHON\" && test_set_prereq PYTHON\n-test -n \"$USE_LIBPCRE\" && test_set_prereq PCRE\n+test -n \"$USE_LIBPCRE1\" && test_set_prereq PCRE\n test -z \"$NO_GETTEXT\" && test_set_prereq GETTEXT\n \n # Can we rely on git's output in the C locale?\n-- \n2.11.0\n\n"},{"id":"317285","messageId":"20170419224053.8920-8-avarab@gmail.com","threadId":"45751","inReplyTo":"20170419224053.8920-1-avarab@gmail.com","subject":"[PATCH v2 07/13] grep: make grep.patternType=[pcre|pcre1] a synonym for \"perl\"","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2017-04-19T22:40:47Z","receivedAt":"2017-04-19T22:41:59Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Make the pattern types \"pcre\" & \"pcre1\" synonyms for the long-standing\n\"perl\" grep.patternType.\n\nThis change is part of a longer patch series to add pcre2 support to\nGit. It's nice to be able to performance test PCRE v1 v.s. v2 without\nhaving to recompile git, and doing that via grep.patternType makes\nsense.\n\nHowever, just adding \"pcre2\" when we only have \"perl\" would be\nconfusing, so start by adding a \"pcre\" & \"pcre1\" synonym.\n\nIn the future \"perl\" and \"pcre\" might be changed to default to \"pcre2\"\ninstead of \"pcre1\", and depending on how Git is compiled the more\nspecific \"pcre1\" or \"pcre2\" pattern types might produce an error.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n Documentation/config.txt |  9 +++++++++\n grep.c                   |  4 +++-\n t/t7810-grep.sh          | 10 ++++++++++\n 3 files changed, 22 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 475e874d51..5ef12d0694 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -1624,6 +1624,15 @@ grep.patternType::\n \t'fixed', or 'perl' will enable the `--basic-regexp`, `--extended-regexp`,\n \t`--fixed-strings`, or `--perl-regexp` option accordingly, while the\n \tvalue 'default' will return to the default matching behavior.\n++\n+The 'pcre' and 'pcre1' values are synonyms for 'perl'. The other\n+values starting with 'pcre' are reserved for future use, e.g. if we'd\n+like to use 'pcre2' for the PCRE v2 library.\n++\n+In the future 'perl' and 'pcre' might become synonyms for some other\n+implementation or PCRE version, such as 'pcre2', while the more\n+specific 'pcre1' & 'pcre2' might throw errors depending on whether git\n+is compiled to include those libraries.\n \n grep.extendedRegexp::\n \tIf set to true, enable `--extended-regexp` option by default. This\ndiff --git a/grep.c b/grep.c\nindex 59ae7809f2..506545c0ee 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -60,7 +60,9 @@ static int parse_pattern_type_arg(const char *opt, const char *arg)\n \t\treturn GREP_PATTERN_TYPE_ERE;\n \telse if (!strcmp(arg, \"fixed\"))\n \t\treturn GREP_PATTERN_TYPE_FIXED;\n-\telse if (!strcmp(arg, \"perl\"))\n+\telse if (!strcmp(arg, \"perl\") ||\n+\t\t !strcmp(arg, \"pcre\") ||\n+\t\t !strcmp(arg, \"pcre1\"))\n \t\treturn GREP_PATTERN_TYPE_PCRE;\n \tdie(\"bad %s argument: %s\", opt, arg);\n }\ndiff --git a/t/t7810-grep.sh b/t/t7810-grep.sh\nindex 8baed0f37d..0fb95c7438 100755\n--- a/t/t7810-grep.sh\n+++ b/t/t7810-grep.sh\n@@ -1512,4 +1512,14 @@ test_expect_success 'grep does not report i-t-a and assume unchanged with -L' '\n \ttest_cmp expected actual\n '\n \n+test_expect_success LIBPCRE \"grep with grep.patternType synonyms perl/pcre/pcre1\" '\n+\techo \"#include <stdio.h>\" >expected &&\n+\tgit -c grep.patternType=perl  grep -h --no-line-number \"st(?=dio)\" >actual &&\n+\ttest_cmp expected actual &&\n+\tgit -c grep.patternType=pcre  grep -h --no-line-number \"st(?=dio)\" >actual &&\n+\ttest_cmp expected actual &&\n+\tgit -c grep.patternType=pcre1 grep -h --no-line-number \"st(?=dio)\" >actual &&\n+\ttest_cmp expected actual\n+'\n+\n test_done\n-- \n2.11.0\n\n"},{"id":"317286","messageId":"20170419224053.8920-11-avarab@gmail.com","threadId":"45751","inReplyTo":"20170419224053.8920-1-avarab@gmail.com","subject":"[PATCH v2 10/13] grep: change the internal PCRE code & header names to be PCRE1","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2017-04-19T22:40:50Z","receivedAt":"2017-04-19T22:42:03Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Change the internal PCRE variable & function names to have a \"1\"\nsuffix. This is for preparation for libpcre2 support, where having\nnon-versioned names would be confusing.\n\nThe earlier \"grep: change the internal PCRE macro names to be PCRE1\"\nchange elaborates on the motivations behind this commit.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n builtin/grep.c |  4 ++--\n grep.c         | 56 ++++++++++++++++++++++++++++----------------------------\n grep.h         | 10 +++++-----\n revision.c     |  2 +-\n 4 files changed, 36 insertions(+), 36 deletions(-)\n\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 65070c52fc..945e9e7f2e 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -490,7 +490,7 @@ static void compile_submodule_options(const struct grep_opt *opt,\n \tcase GREP_PATTERN_TYPE_FIXED:\n \t\targv_array_push(&submodule_options, \"-F\");\n \t\tbreak;\n-\tcase GREP_PATTERN_TYPE_PCRE:\n+\tcase GREP_PATTERN_TYPE_PCRE1:\n \t\targv_array_push(&submodule_options, \"-P\");\n \t\tbreak;\n \tcase GREP_PATTERN_TYPE_UNSPECIFIED:\n@@ -1018,7 +1018,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\t\t    GREP_PATTERN_TYPE_FIXED),\n \t\tOPT_SET_INT('P', \"perl-regexp\", &pattern_type_arg,\n \t\t\t    N_(\"use Perl-compatible regular expressions\"),\n-\t\t\t    GREP_PATTERN_TYPE_PCRE),\n+\t\t\t    GREP_PATTERN_TYPE_PCRE1),\n \t\tOPT_GROUP(\"\"),\n \t\tOPT_BOOL('n', \"line-number\", &opt.linenum, N_(\"show line numbers\")),\n \t\tOPT_NEGBIT('h', NULL, &opt.pathname, N_(\"don't show filenames\"), 1),\ndiff --git a/grep.c b/grep.c\nindex 2535abd214..d2c87ee2c3 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -63,7 +63,7 @@ static int parse_pattern_type_arg(const char *opt, const char *arg)\n \telse if (!strcmp(arg, \"perl\") ||\n \t\t !strcmp(arg, \"pcre\") ||\n \t\t !strcmp(arg, \"pcre1\"))\n-\t\treturn GREP_PATTERN_TYPE_PCRE;\n+\t\treturn GREP_PATTERN_TYPE_PCRE1;\n \tdie(\"bad %s argument: %s\", opt, arg);\n }\n \n@@ -180,25 +180,25 @@ static void grep_set_pattern_type_option(enum grep_pattern_type pattern_type, st\n \n \tcase GREP_PATTERN_TYPE_BRE:\n \t\topt->fixed = 0;\n-\t\topt->pcre = 0;\n+\t\topt->pcre1 = 0;\n \t\topt->regflags &= ~REG_EXTENDED;\n \t\tbreak;\n \n \tcase GREP_PATTERN_TYPE_ERE:\n \t\topt->fixed = 0;\n-\t\topt->pcre = 0;\n+\t\topt->pcre1 = 0;\n \t\topt->regflags |= REG_EXTENDED;\n \t\tbreak;\n \n \tcase GREP_PATTERN_TYPE_FIXED:\n \t\topt->fixed = 1;\n-\t\topt->pcre = 0;\n+\t\topt->pcre1 = 0;\n \t\topt->regflags &= ~REG_EXTENDED;\n \t\tbreak;\n \n-\tcase GREP_PATTERN_TYPE_PCRE:\n+\tcase GREP_PATTERN_TYPE_PCRE1:\n \t\topt->fixed = 0;\n-\t\topt->pcre = 1;\n+\t\topt->pcre1 = 1;\n \t\tbreak;\n \t}\n }\n@@ -326,7 +326,7 @@ static NORETURN void compile_regexp_failed(const struct grep_pat *p,\n }\n \n #ifdef USE_LIBPCRE1\n-static void compile_pcre_regexp(struct grep_pat *p, const struct grep_opt *opt)\n+static void compile_pcre1_regexp(struct grep_pat *p, const struct grep_opt *opt)\n {\n \tconst char *error;\n \tint erroffset;\n@@ -334,23 +334,23 @@ static void compile_pcre_regexp(struct grep_pat *p, const struct grep_opt *opt)\n \n \tif (opt->ignore_case) {\n \t\tif (has_non_ascii(p->pattern))\n-\t\t\tp->pcre_tables = pcre_maketables();\n+\t\t\tp->pcre1_tables = pcre_maketables();\n \t\toptions |= PCRE_CASELESS;\n \t}\n \tif (is_utf8_locale() && has_non_ascii(p->pattern))\n \t\toptions |= PCRE_UTF8;\n \n-\tp->pcre_regexp = pcre_compile(p->pattern, options, &error, &erroffset,\n-\t\t\t\t      p->pcre_tables);\n-\tif (!p->pcre_regexp)\n+\tp->pcre1_regexp = pcre_compile(p->pattern, options, &error, &erroffset,\n+\t\t\t\t      p->pcre1_tables);\n+\tif (!p->pcre1_regexp)\n \t\tcompile_regexp_failed(p, error);\n \n-\tp->pcre_extra_info = pcre_study(p->pcre_regexp, 0, &error);\n-\tif (!p->pcre_extra_info && error)\n+\tp->pcre1_extra_info = pcre_study(p->pcre1_regexp, 0, &error);\n+\tif (!p->pcre1_extra_info && error)\n \t\tdie(\"%s\", error);\n }\n \n-static int pcrematch(struct grep_pat *p, const char *line, const char *eol,\n+static int pcre1match(struct grep_pat *p, const char *line, const char *eol,\n \t\tregmatch_t *match, int eflags)\n {\n \tint ovector[30], ret, flags = 0;\n@@ -358,7 +358,7 @@ static int pcrematch(struct grep_pat *p, const char *line, const char *eol,\n \tif (eflags & REG_NOTBOL)\n \t\tflags |= PCRE_NOTBOL;\n \n-\tret = pcre_exec(p->pcre_regexp, p->pcre_extra_info, line, eol - line,\n+\tret = pcre_exec(p->pcre1_regexp, p->pcre1_extra_info, line, eol - line,\n \t\t\t0, flags, ovector, ARRAY_SIZE(ovector));\n \tif (ret < 0 && ret != PCRE_ERROR_NOMATCH)\n \t\tdie(\"pcre_exec failed with error code %d\", ret);\n@@ -371,25 +371,25 @@ static int pcrematch(struct grep_pat *p, const char *line, const char *eol,\n \treturn ret;\n }\n \n-static void free_pcre_regexp(struct grep_pat *p)\n+static void free_pcre1_regexp(struct grep_pat *p)\n {\n-\tpcre_free(p->pcre_regexp);\n-\tpcre_free(p->pcre_extra_info);\n-\tpcre_free((void *)p->pcre_tables);\n+\tpcre_free(p->pcre1_regexp);\n+\tpcre_free(p->pcre1_extra_info);\n+\tpcre_free((void *)p->pcre1_tables);\n }\n #else /* !USE_LIBPCRE1 */\n-static void compile_pcre_regexp(struct grep_pat *p, const struct grep_opt *opt)\n+static void compile_pcre1_regexp(struct grep_pat *p, const struct grep_opt *opt)\n {\n \tdie(\"cannot use Perl-compatible regexes when not compiled with USE_LIBPCRE\");\n }\n \n-static int pcrematch(struct grep_pat *p, const char *line, const char *eol,\n+static int pcre1match(struct grep_pat *p, const char *line, const char *eol,\n \t\tregmatch_t *match, int eflags)\n {\n \treturn 1;\n }\n \n-static void free_pcre_regexp(struct grep_pat *p)\n+static void free_pcre1_regexp(struct grep_pat *p)\n {\n }\n #endif /* !USE_LIBPCRE1 */\n@@ -476,8 +476,8 @@ static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)\n \t\treturn;\n \t}\n \n-\tif (opt->pcre) {\n-\t\tcompile_pcre_regexp(p, opt);\n+\tif (opt->pcre1) {\n+\t\tcompile_pcre1_regexp(p, opt);\n \t\treturn;\n \t}\n \n@@ -833,8 +833,8 @@ void free_grep_patterns(struct grep_opt *opt)\n \t\tcase GREP_PATTERN_BODY:\n \t\t\tif (p->kws)\n \t\t\t\tkwsfree(p->kws);\n-\t\t\telse if (p->pcre_regexp)\n-\t\t\t\tfree_pcre_regexp(p);\n+\t\t\telse if (p->pcre1_regexp)\n+\t\t\t\tfree_pcre1_regexp(p);\n \t\t\telse\n \t\t\t\tregfree(&p->regexp);\n \t\t\tfree(p->pattern);\n@@ -913,8 +913,8 @@ static int patmatch(struct grep_pat *p, char *line, char *eol,\n \n \tif (p->fixed)\n \t\thit = !fixmatch(p, line, eol, match);\n-\telse if (p->pcre_regexp)\n-\t\thit = !pcrematch(p, line, eol, match, eflags);\n+\telse if (p->pcre1_regexp)\n+\t\thit = !pcre1match(p, line, eol, match, eflags);\n \telse\n \t\thit = !regexec_buf(&p->regexp, line, eol - line, 1, match,\n \t\t\t\t   eflags);\ndiff --git a/grep.h b/grep.h\nindex 073b0e4c92..fa2ab9485f 100644\n--- a/grep.h\n+++ b/grep.h\n@@ -46,9 +46,9 @@ struct grep_pat {\n \tsize_t patternlen;\n \tenum grep_header_field field;\n \tregex_t regexp;\n-\tpcre *pcre_regexp;\n-\tpcre_extra *pcre_extra_info;\n-\tconst unsigned char *pcre_tables;\n+\tpcre *pcre1_regexp;\n+\tpcre_extra *pcre1_extra_info;\n+\tconst unsigned char *pcre1_tables;\n \tkwset_t kws;\n \tunsigned fixed:1;\n \tunsigned ignore_case:1;\n@@ -68,7 +68,7 @@ enum grep_pattern_type {\n \tGREP_PATTERN_TYPE_BRE,\n \tGREP_PATTERN_TYPE_ERE,\n \tGREP_PATTERN_TYPE_FIXED,\n-\tGREP_PATTERN_TYPE_PCRE\n+\tGREP_PATTERN_TYPE_PCRE1\n };\n \n struct grep_expr {\n@@ -111,7 +111,7 @@ struct grep_opt {\n \tint allow_textconv;\n \tint extended;\n \tint use_reflog_filter;\n-\tint pcre;\n+\tint pcre1;\n \tint relative;\n \tint pathname;\n \tint null_following_name;\ndiff --git a/revision.c b/revision.c\nindex 03a3a012de..7a10a8570a 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -1996,7 +1996,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg\n \t} else if (!strcmp(arg, \"--fixed-strings\") || !strcmp(arg, \"-F\")) {\n \t\trevs->grep_filter.pattern_type_option = GREP_PATTERN_TYPE_FIXED;\n \t} else if (!strcmp(arg, \"--perl-regexp\") || !strcmp(arg, \"-P\")) {\n-\t\trevs->grep_filter.pattern_type_option = GREP_PATTERN_TYPE_PCRE;\n+\t\trevs->grep_filter.pattern_type_option = GREP_PATTERN_TYPE_PCRE1;\n \t} else if (!strcmp(arg, \"--all-match\")) {\n \t\trevs->grep_filter.all_match = 1;\n \t} else if (!strcmp(arg, \"--invert-grep\")) {\n-- \n2.11.0\n\n"},{"id":"317287","messageId":"20170419224053.8920-12-avarab@gmail.com","threadId":"45751","inReplyTo":"20170419224053.8920-1-avarab@gmail.com","subject":"[PATCH v2 11/13] perf: add a performance comparison test of grep -E and -P","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2017-04-19T22:40:51Z","receivedAt":"2017-04-19T22:42:05Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Add a very basic performance comparison test comparing the POSIX\nextended & pcre1 engines.\n\nI'm skipping the \"basic\" POSIX engine because supporting its alternate\nregex syntax is hard, although it would be interesting to test it, at\nleast under glibc it seems to be an entirely different engine, since\nit can have very different performance even for patterns that mean the\nsame thing under extended and non-extended POSIX regular expression\nsyntax.\n\nRunning this on an i7 3.4GHz Linux 3.16.0-4 Debian testing against a\ncheckout of linux.git & latest upstream PCRE, both PCRE and git\ncompiled with -O3:\n\n    $ GIT_PERF_LARGE_REPO=~/g/linux ./run p7820-grep-engines.sh\n    [...]\n    Test                                                       this tree\n    -----------------------------------------------------------------------------\n    7820.1: extended with how.to                               0.28(1.23+0.44)\n    7820.2: extended with ^how to                              0.26(1.15+0.38)\n    7820.3: extended with \\w+our\\w*                            6.06(38.44+0.35)\n    7820.4: extended with -?-?-?-?-?-?-?-?-?-?-?-----------$   0.37(1.57+0.38)\n    7820.5: pcre1 with how.to                                  0.26(1.15+0.37)\n    7820.6: pcre1 with ^how to                                 0.46(2.66+0.31)\n    7820.7: pcre1 with \\w+our\\w*                               16.42(99.42+0.48)\n    7820.8: pcre1 with -?-?-?-?-?-?-?-?-?-?-?-----------$      81.52(275.37+0.41)\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n t/perf/p7820-grep-engines.sh | 25 +++++++++++++++++++++++++\n 1 file changed, 25 insertions(+)\n create mode 100755 t/perf/p7820-grep-engines.sh\n\ndiff --git a/t/perf/p7820-grep-engines.sh b/t/perf/p7820-grep-engines.sh\nnew file mode 100755\nindex 0000000000..5ae42ceccc\n--- /dev/null\n+++ b/t/perf/p7820-grep-engines.sh\n@@ -0,0 +1,25 @@\n+#!/bin/sh\n+\n+test_description=\"Comparison of git-grep's regex engines\"\n+\n+. ./perf-lib.sh\n+\n+test_perf_large_repo\n+test_checkout_worktree\n+\n+for engine in extended pcre1\n+do\n+\t# Patterns stolen from http://sljit.sourceforge.net/pcre.html\n+\tfor pattern in \\\n+\t\t'how.to' \\\n+\t\t'^how to' \\\n+\t\t'\\w+our\\w*' \\\n+\t\t'-?-?-?-?-?-?-?-?-?-?-?-----------$'\n+\tdo\n+\t\ttest_perf \"$engine with $pattern\" \"\n+\t\t\tgit -c grep.patternType=$engine grep -- '$pattern' || :\n+\t\t\"\n+\tdone\n+done\n+\n+test_done\n-- \n2.11.0\n\n"},{"id":"317288","messageId":"20170419224053.8920-13-avarab@gmail.com","threadId":"45751","inReplyTo":"20170419224053.8920-1-avarab@gmail.com","subject":"[PATCH v2 12/13] grep: add support for the PCRE v1 JIT API","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2017-04-19T22:40:52Z","receivedAt":"2017-04-19T22:42:11Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Change the grep PCRE v1 code to use JIT when available. When PCRE\nsupport was initially added in commit 63e7e9d8b6 (\"git-grep: Learn\nPCRE\", 2011-05-09) PCRE had no JIT support, it was integrated into\n8.20 released on 2011-10-21.\n\nWhen JIT support is enabled the PCRE performance usually improves by\nmore than 50%. The pattern compilation times are relatively slower,\nbut those relative numbers are tiny, and are easily made back in all\nbut the most trivial cases of grep. Detailed benchhmarks are available\nat: http://sljit.sourceforge.net/pcre.html\n\nWith this change the difference in a t/perf/p7820-grep-engines.sh run\nis, shown with git --word-diff:\n\n    7820.1: extended with how.to                               [-0.28(1.23+0.44)-]{+0.28(1.18+0.39)+}\n    7820.2: extended with ^how to                              [-0.26(1.15+0.38)-]{+0.27(1.13+0.40)+}\n    7820.3: extended with \\w+our\\w*                            [-6.06(38.44+0.35)-]{+6.11(38.66+0.32)+}\n    7820.4: extended with -?-?-?-?-?-?-?-?-?-?-?-----------$   [-0.37(1.57+0.38)-]{+0.37(1.56+0.42)+}\n    7820.5: pcre1 with how.to                                  [-0.26(1.15+0.37)-]{+0.19(0.39+0.55)+}\n    7820.6: pcre1 with ^how to                                 [-0.46(2.66+0.31)-]{+0.22(0.67+0.44)+}\n    7820.7: pcre1 with \\w+our\\w*                               [-16.42(99.42+0.48)-]{+0.51(3.05+0.24)+}\n    7820.8: pcre1 with -?-?-?-?-?-?-?-?-?-?-?-----------$      [-81.52(275.37+0.41)-]{+5.16(19.31+0.33)+}\n\nThe conditional support for JIT is implemented as suggested in the\npcrejit(3) man page. E.g. defining PCRE_STUDY_JIT_COMPILE to 0 if it's\nnot present.\n\nThere's no graceful fallback if pcre_jit_stack_alloc() fails under\nPCRE_CONFIG_JIT, instead the program will abort. I don't think this is\nworth handling, it'll only fail in cases where malloc() doesn't work,\nin which case we're screwed anyway.\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n grep.c | 27 ++++++++++++++++++++++++++-\n grep.h |  5 +++++\n 2 files changed, 31 insertions(+), 1 deletion(-)\n\ndiff --git a/grep.c b/grep.c\nindex d2c87ee2c3..eb68bdaa2a 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -331,6 +331,9 @@ static void compile_pcre1_regexp(struct grep_pat *p, const struct grep_opt *opt)\n \tconst char *error;\n \tint erroffset;\n \tint options = PCRE_MULTILINE;\n+#ifdef PCRE_CONFIG_JIT\n+\tint canjit;\n+#endif\n \n \tif (opt->ignore_case) {\n \t\tif (has_non_ascii(p->pattern))\n@@ -345,9 +348,19 @@ static void compile_pcre1_regexp(struct grep_pat *p, const struct grep_opt *opt)\n \tif (!p->pcre1_regexp)\n \t\tcompile_regexp_failed(p, error);\n \n-\tp->pcre1_extra_info = pcre_study(p->pcre1_regexp, 0, &error);\n+\tp->pcre1_extra_info = pcre_study(p->pcre1_regexp, PCRE_STUDY_JIT_COMPILE, &error);\n \tif (!p->pcre1_extra_info && error)\n \t\tdie(\"%s\", error);\n+\n+#ifdef PCRE_CONFIG_JIT\n+\tpcre_config(PCRE_CONFIG_JIT, &canjit);\n+\tif (canjit == 1) {\n+\t\tp->pcre1_jit_stack = pcre_jit_stack_alloc(1, 1024 * 1024);\n+\t\tif (!p->pcre1_jit_stack)\n+\t\t\tdie(\"BUG: Couldn't allocate PCRE JIT stack\");\n+\t\tpcre_assign_jit_stack(p->pcre1_extra_info, NULL, p->pcre1_jit_stack);\n+\t}\n+#endif\n }\n \n static int pcre1match(struct grep_pat *p, const char *line, const char *eol,\n@@ -358,8 +371,15 @@ static int pcre1match(struct grep_pat *p, const char *line, const char *eol,\n \tif (eflags & REG_NOTBOL)\n \t\tflags |= PCRE_NOTBOL;\n \n+#ifdef PCRE_CONFIG_JIT\n+\tret = pcre_jit_exec(p->pcre1_regexp, p->pcre1_extra_info, line, eol - line,\n+\t\t\t    0, flags, ovector, ARRAY_SIZE(ovector),\n+\t\t\t    p->pcre1_jit_stack);\n+#else\n \tret = pcre_exec(p->pcre1_regexp, p->pcre1_extra_info, line, eol - line,\n \t\t\t0, flags, ovector, ARRAY_SIZE(ovector));\n+#endif\n+\n \tif (ret < 0 && ret != PCRE_ERROR_NOMATCH)\n \t\tdie(\"pcre_exec failed with error code %d\", ret);\n \tif (ret > 0) {\n@@ -374,7 +394,12 @@ static int pcre1match(struct grep_pat *p, const char *line, const char *eol,\n static void free_pcre1_regexp(struct grep_pat *p)\n {\n \tpcre_free(p->pcre1_regexp);\n+#ifdef PCRE_CONFIG_JIT\n+\tpcre_free_study(p->pcre1_extra_info);\n+\tpcre_jit_stack_free(p->pcre1_jit_stack);\n+#else\n \tpcre_free(p->pcre1_extra_info);\n+#endif\n \tpcre_free((void *)p->pcre1_tables);\n }\n #else /* !USE_LIBPCRE1 */\ndiff --git a/grep.h b/grep.h\nindex fa2ab9485f..29e20bf837 100644\n--- a/grep.h\n+++ b/grep.h\n@@ -3,9 +3,13 @@\n #include \"color.h\"\n #ifdef USE_LIBPCRE1\n #include <pcre.h>\n+#ifndef PCRE_STUDY_JIT_COMPILE\n+#define PCRE_STUDY_JIT_COMPILE 0\n+#endif\n #else\n typedef int pcre;\n typedef int pcre_extra;\n+typedef int pcre_jit_stack;\n #endif\n #include \"kwset.h\"\n #include \"thread-utils.h\"\n@@ -48,6 +52,7 @@ struct grep_pat {\n \tregex_t regexp;\n \tpcre *pcre1_regexp;\n \tpcre_extra *pcre1_extra_info;\n+\tpcre_jit_stack *pcre1_jit_stack;\n \tconst unsigned char *pcre1_tables;\n \tkwset_t kws;\n \tunsigned fixed:1;\n-- \n2.11.0\n\n"},{"id":"317289","messageId":"20170419224053.8920-14-avarab@gmail.com","threadId":"45751","inReplyTo":"20170419224053.8920-1-avarab@gmail.com","subject":"[PATCH v2 13/13] grep: add support for PCRE v2","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2017-04-19T22:40:53Z","receivedAt":"2017-04-19T22:42:14Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Add support for v2 of the PCRE API. This is a new major version of\nPCRE that came out in early 2015[1].\n\nThe regular expression syntax is the same, but while the API is\nsimilar-ish, pretty much every function is either renamed or takes\ndifferent arguments. Thus using it via entirely new functions makes\nsense, as opposed to trying to e.g. have one compile_pcre_pattern()\nthat would call either PCRE v1 or v2 functions.\n\nGit can now be compiled with any combination of\nUSE_LIBPCRE=[YesPlease|] & USE_LIBPCRE2=[YesPlease|]. If both are\nprovided the version of the PCRE library can be selected at runtime\nwith grep.PatternType, but the default (for now) is v1.\n\nThis table shows what the various combinations do, depending on what\nlibraries Git is compiled against:\n\n    |------------------+-----+-----+----------|\n    | grep.PatternType | v1  | v2  | v1 && v2 |\n    |------------------+-----+-----+----------|\n    | perl             | v1  | v2  | v1       |\n    | pcre             | v1  | v2  | v1       |\n    | pcre1            | v1  | ERR | v1       |\n    | pcre2            | ERR | v2  | v2       |\n    |------------------+-----+-----+----------|\n\nWhen Git is only compiled with v2 grep.PatternType=perl, --perl-regexp\n& -P will use v2. All tests pass with this new PCRE version. When Git\nis compiled with both v1 & v2 most of the tests will only test v1, but\nthere are some v2-specific tests that will be run.\n\nWith earlier patches to enable JIT for PCRE v1 the performance of the\nrelease versions of both libraries have almost exactly the same\nperformance, with PCRE v2 being around 1% slower.\n\nHowever after I reported this to the pcre-dev mailing list[2] I got a\nlot of help with the API use from Zoltán Herczeg, he\nsubsequently optimized some of the JIT functionality in v2 of the\nlibrary.\n\nRunning the p7820-grep-engines.sh performance test against the latest\nSubversion trunk of both, with both them and git compiled as -O3, and\nthe test run against linux.git, gives the following results:\n\n    7820.1: extended with how.to                               0.27(1.22+0.34)\n    7820.2: extended with ^how to                              0.27(1.18+0.36)\n    7820.3: extended with \\w+our\\w*                            6.09(38.64+0.32)\n    7820.4: extended with -?-?-?-?-?-?-?-?-?-?-?-----------$   0.38(1.69+0.28)\n    7820.5: pcre1 with how.to                                  0.19(0.42+0.53)\n    7820.6: pcre1 with ^how to                                 0.23(0.58+0.50)\n    7820.7: pcre1 with \\w+our\\w*                               0.50(2.93+0.34)\n    7820.8: pcre1 with -?-?-?-?-?-?-?-?-?-?-?-----------$      5.12(19.32+0.38)\n    7820.9: pcre2 with how.to                                  0.19(0.34+0.57)\n    7820.10: pcre2 with ^how to                                0.19(0.29+0.60)\n    7820.11: pcre2 with \\w+our\\w*                              0.51(2.85+0.41)\n    7820.12: pcre2 with -?-?-?-?-?-?-?-?-?-?-?-----------$     5.04(19.27+0.31)\n\nI.e. the two are neck-to-neck, but PCRE v2 usually pulls ahead, when\nit does it's up to 20% faster.\n\nA brief note on thread safety: As noted in pcre2api(3) & pcre2jit(3)\nthe compiled pattern can be shared between threads, but not some of\nthe JIT context, however the grep threading support does all pattern &\nJIT compilation in separate threads, so this code doesn't need to\nconcern itself with thread safety.\n\nSee commit 63e7e9d8b6 (\"git-grep: Learn PCRE\", 2011-05-09) for the\ninitial addition of PCRE v1. This change follows some of the same\npatterns it did (and which were discussed on list at the time),\ne.g. mocking up types with typedef instead of ifdef-ing them out when\nUSE_LIBPCRE2 isn't defined. This adds some trivial memory use to the\nprogram, but makes the code look nicer.\n\n1. https://lists.exim.org/lurker/message/20150105.162835.0666407a.en.html\n2. https://lists.exim.org/lurker/thread/20170419.172322.833ee099.en.html\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n Documentation/config.txt     |  14 ++--\n Makefile                     |  18 ++++++\n builtin/grep.c               |   4 +-\n configure.ac                 |  49 +++++++++++++-\n grep.c                       | 149 ++++++++++++++++++++++++++++++++++++++++++-\n grep.h                       |  21 +++++-\n revision.c                   |   2 +-\n t/README                     |  12 ++++\n t/perf/p7820-grep-engines.sh |   2 +-\n t/t7810-grep.sh              |  30 ++++++++-\n t/t7813-grep-icase-iso.sh    |  11 ++--\n t/test-lib.sh                |   4 +-\n 12 files changed, 291 insertions(+), 25 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 5ef12d0694..a5fc482495 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -1625,14 +1625,12 @@ grep.patternType::\n \t`--fixed-strings`, or `--perl-regexp` option accordingly, while the\n \tvalue 'default' will return to the default matching behavior.\n +\n-The 'pcre' and 'pcre1' values are synonyms for 'perl'. The other\n-values starting with 'pcre' are reserved for future use, e.g. if we'd\n-like to use 'pcre2' for the PCRE v2 library.\n-+\n-In the future 'perl' and 'pcre' might become synonyms for some other\n-implementation or PCRE version, such as 'pcre2', while the more\n-specific 'pcre1' & 'pcre2' might throw errors depending on whether git\n-is compiled to include those libraries.\n+The 'perl' and 'pcre' values are synonyms. Depending on which PCRE\n+library Git was compiled with either or both of 'pcre1' and 'pcre2'\n+might also be available.\n++\n+If both are available Git currently defaults to 'pcre1', but this\n+might change in future versions.\n \n grep.extendedRegexp::\n \tIf set to true, enable `--extended-regexp` option by default. This\ndiff --git a/Makefile b/Makefile\nindex cd19980906..6eba4e40e3 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -32,6 +32,14 @@ all::\n # Define LIBPCREDIR=/foo/bar if your libpcre header and library files are in\n # /foo/bar/include and /foo/bar/lib directories.\n #\n+# Define USE_LIBPCRE2 if you have and want to use libpcre2. Various\n+# commands such as log and grep offer runtime options to use\n+# Perl-compatible regular expressions instead of standard or extended\n+# POSIX regular expressions.\n+#\n+# Define LIBPCRE2DIR=/foo/bar if your libpcre2 header and library\n+# files are in /foo/bar/include and /foo/bar/lib directories.\n+#\n # Define HAVE_ALLOCA_H if you have working alloca(3) defined in that header.\n #\n # Define NO_CURL if you do not have libcurl installed.  git-http-fetch and\n@@ -1092,6 +1100,15 @@ ifdef USE_LIBPCRE\n \tEXTLIBS += -lpcre\n endif\n \n+ifdef USE_LIBPCRE2\n+\tBASIC_CFLAGS += -DUSE_LIBPCRE2\n+\tifdef LIBPCRE2DIR\n+\t\tBASIC_CFLAGS += -I$(LIBPCRE2DIR)/include\n+\t\tEXTLIBS += -L$(LIBPCRE2DIR)/$(lib) $(CC_LD_DYNPATH)$(LIBPCR2EDIR)/$(lib)\n+\tendif\n+\tEXTLIBS += -lpcre2-8\n+endif\n+\n ifdef HAVE_ALLOCA_H\n \tBASIC_CFLAGS += -DHAVE_ALLOCA_H\n endif\n@@ -2237,6 +2254,7 @@ GIT-BUILD-OPTIONS: FORCE\n \t@echo NO_CURL=\\''$(subst ','\\'',$(subst ','\\'',$(NO_CURL)))'\\' >>$@+\n \t@echo NO_EXPAT=\\''$(subst ','\\'',$(subst ','\\'',$(NO_EXPAT)))'\\' >>$@+\n \t@echo USE_LIBPCRE1=\\''$(subst ','\\'',$(subst ','\\'',$(USE_LIBPCRE)))'\\' >>$@+\n+\t@echo USE_LIBPCRE2=\\''$(subst ','\\'',$(subst ','\\'',$(USE_LIBPCRE2)))'\\' >>$@+\n \t@echo NO_PERL=\\''$(subst ','\\'',$(subst ','\\'',$(NO_PERL)))'\\' >>$@+\n \t@echo NO_PYTHON=\\''$(subst ','\\'',$(subst ','\\'',$(NO_PYTHON)))'\\' >>$@+\n \t@echo NO_UNIX_SOCKETS=\\''$(subst ','\\'',$(subst ','\\'',$(NO_UNIX_SOCKETS)))'\\' >>$@+\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 945e9e7f2e..65070c52fc 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -490,7 +490,7 @@ static void compile_submodule_options(const struct grep_opt *opt,\n \tcase GREP_PATTERN_TYPE_FIXED:\n \t\targv_array_push(&submodule_options, \"-F\");\n \t\tbreak;\n-\tcase GREP_PATTERN_TYPE_PCRE1:\n+\tcase GREP_PATTERN_TYPE_PCRE:\n \t\targv_array_push(&submodule_options, \"-P\");\n \t\tbreak;\n \tcase GREP_PATTERN_TYPE_UNSPECIFIED:\n@@ -1018,7 +1018,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\t\t    GREP_PATTERN_TYPE_FIXED),\n \t\tOPT_SET_INT('P', \"perl-regexp\", &pattern_type_arg,\n \t\t\t    N_(\"use Perl-compatible regular expressions\"),\n-\t\t\t    GREP_PATTERN_TYPE_PCRE1),\n+\t\t\t    GREP_PATTERN_TYPE_PCRE),\n \t\tOPT_GROUP(\"\"),\n \t\tOPT_BOOL('n', \"line-number\", &opt.linenum, N_(\"show line numbers\")),\n \t\tOPT_NEGBIT('h', NULL, &opt.pathname, N_(\"don't show filenames\"), 1),\ndiff --git a/configure.ac b/configure.ac\nindex deeb968daa..725c2d6949 100644\n--- a/configure.ac\n+++ b/configure.ac\n@@ -259,8 +259,8 @@ GIT_PARSE_WITH([openssl]))\n # /foo/bar/include and /foo/bar/lib directories.\n #\n AC_ARG_WITH(libpcre,\n-AS_HELP_STRING([--with-libpcre],[support Perl-compatible regexes (default is NO)])\n-AS_HELP_STRING([],           [ARG can be also prefix for libpcre library and headers]),\n+AS_HELP_STRING([--with-libpcre],[support Perl-compatible regexes via libpcre1 (default is NO)])\n+AS_HELP_STRING([],           [ARG can be also prefix for libpcre1 library and headers]),\n     if test \"$withval\" = \"no\"; then\n \tUSE_LIBPCRE=\n     elif test \"$withval\" = \"yes\"; then\n@@ -273,6 +273,30 @@ AS_HELP_STRING([],           [ARG can be also prefix for libpcre library and hea\n         dnl it yet.\n \tGIT_CONF_SUBST([LIBPCREDIR])\n     fi)\n+\n+# Define USE_LIBPCRE2 if you have and want to use libpcre2. Various\n+# commands such as log and grep offer runtime options to use\n+# Perl-compatible regular expressions instead of standard or extended\n+# POSIX regular expressions.\n+#\n+# Define LIBPCR2EDIR=/foo/bar if your libpcre2 header and library\n+# files are in /foo/bar/include and /foo/bar/lib directories.\n+#\n+AC_ARG_WITH(libpcre2,\n+AS_HELP_STRING([--with-libpcre2],[support Perl-compatible regexes via libpcre2 (default is NO)])\n+AS_HELP_STRING([],           [ARG can be also prefix for libpcre library and headers]),\n+    if test \"$withval\" = \"no\"; then\n+\tUSE_LIBPCRE2=\n+    elif test \"$withval\" = \"yes\"; then\n+\tUSE_LIBPCRE2=YesPlease\n+    else\n+\tUSE_LIBPCRE2=YesPlease\n+\tLIBPCRE2DIR=$withval\n+\tAC_MSG_NOTICE([Setting LIBPCRE2DIR to $LIBPCREDIR])\n+        dnl USE_LIBPCRE2 can still be modified below, so don't substitute\n+        dnl it yet.\n+\tGIT_CONF_SUBST([LIBPCRE2DIR])\n+    fi)\n #\n # Define HAVE_ALLOCA_H if you have working alloca(3) defined in that header.\n AC_FUNC_ALLOCA\n@@ -522,6 +546,27 @@ GIT_CONF_SUBST([USE_LIBPCRE])\n fi\n \n #\n+# Define USE_LIBPCRE2 if you have and want to use libpcre2. Various\n+# commands such as log and grep offer runtime options to use\n+# Perl-compatible regular expressions instead of standard or extended\n+# POSIX regular expressions.\n+#\n+\n+if test -n \"$USE_LIBPCRE2\"; then\n+\n+GIT_STASH_FLAGS($LIBPCRE2DIR)\n+\n+AC_CHECK_LIB([pcre2-8], [pcre2_config_8],\n+[USE_LIBPCRE2=YesPlease],\n+[USE_LIBPCRE2=])\n+\n+GIT_UNSTASH_FLAGS($LIBPCRE2DIR)\n+\n+GIT_CONF_SUBST([USE_LIBPCRE2])\n+\n+fi\n+\n+#\n # Define NO_CURL if you do not have libcurl installed.  git-http-pull and\n # git-http-push are not built, and you cannot use http:// and https://\n # transports.\ndiff --git a/grep.c b/grep.c\nindex eb68bdaa2a..39955f5745 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -61,9 +61,12 @@ static int parse_pattern_type_arg(const char *opt, const char *arg)\n \telse if (!strcmp(arg, \"fixed\"))\n \t\treturn GREP_PATTERN_TYPE_FIXED;\n \telse if (!strcmp(arg, \"perl\") ||\n-\t\t !strcmp(arg, \"pcre\") ||\n-\t\t !strcmp(arg, \"pcre1\"))\n+\t\t !strcmp(arg, \"pcre\"))\n+\t\treturn GREP_PATTERN_TYPE_PCRE;\n+\telse if (!strcmp(arg, \"pcre1\"))\n \t\treturn GREP_PATTERN_TYPE_PCRE1;\n+\telse if (!strcmp(arg, \"pcre2\"))\n+\t\treturn GREP_PATTERN_TYPE_PCRE2;\n \tdie(\"bad %s argument: %s\", opt, arg);\n }\n \n@@ -181,24 +184,48 @@ static void grep_set_pattern_type_option(enum grep_pattern_type pattern_type, st\n \tcase GREP_PATTERN_TYPE_BRE:\n \t\topt->fixed = 0;\n \t\topt->pcre1 = 0;\n+\t\topt->pcre2 = 0;\n \t\topt->regflags &= ~REG_EXTENDED;\n \t\tbreak;\n \n \tcase GREP_PATTERN_TYPE_ERE:\n \t\topt->fixed = 0;\n \t\topt->pcre1 = 0;\n+\t\topt->pcre2 = 0;\n \t\topt->regflags |= REG_EXTENDED;\n \t\tbreak;\n \n \tcase GREP_PATTERN_TYPE_FIXED:\n \t\topt->fixed = 1;\n \t\topt->pcre1 = 0;\n+\t\topt->pcre2 = 0;\n \t\topt->regflags &= ~REG_EXTENDED;\n \t\tbreak;\n \n+\tcase GREP_PATTERN_TYPE_PCRE:\n+\t\topt->fixed = 0;\n+\t\t/* We default to pcre1 if we have both versions. This\n+\t\t * may change in future versions.\n+\t\t */\n+#ifdef USE_LIBPCRE1\n+\t\topt->pcre1 = 1;\n+\t\topt->pcre2 = 0;\n+#elif USE_LIBPCRE2\n+\t\topt->pcre1 = 0;\n+\t\topt->pcre2 = 1;\n+#endif\n+\t\tbreak;\n+\n \tcase GREP_PATTERN_TYPE_PCRE1:\n \t\topt->fixed = 0;\n \t\topt->pcre1 = 1;\n+\t\topt->pcre2 = 0;\n+\t\tbreak;\n+\n+\tcase GREP_PATTERN_TYPE_PCRE2:\n+\t\topt->fixed = 0;\n+\t\topt->pcre1 = 0;\n+\t\topt->pcre2 = 1;\n \t\tbreak;\n \t}\n }\n@@ -419,6 +446,115 @@ static void free_pcre1_regexp(struct grep_pat *p)\n }\n #endif /* !USE_LIBPCRE1 */\n \n+#ifdef USE_LIBPCRE2\n+static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt)\n+{\n+\tint error;\n+\tPCRE2_UCHAR errbuf[256];\n+\tPCRE2_SIZE erroffset;\n+\tint options = PCRE2_MULTILINE;\n+\tconst uint8_t *character_tables = NULL;\n+\tuint32_t canjit;\n+\tint jitret;\n+\n+\tp->pcre2_ccontext = NULL;\n+\n+\tif (opt->ignore_case) {\n+\t\tif (has_non_ascii(p->pattern)) {\n+\t\t\tcharacter_tables = pcre2_maketables(NULL);\n+\t\t\tp->pcre2_ccontext = pcre2_compile_context_create(NULL);\n+\t\t\tpcre2_set_character_tables(p->pcre2_ccontext, character_tables);\n+\t\t}\n+\t\toptions |= PCRE2_CASELESS;\n+\t}\n+\tif (is_utf8_locale() && has_non_ascii(p->pattern))\n+\t\toptions |= PCRE2_UTF;\n+\n+\tp->pcre2_pattern = pcre2_compile((PCRE2_SPTR)p->pattern,\n+\t\t\t\t\t p->patternlen, options, &error, &erroffset,\n+\t\t\t\t\t p->pcre2_ccontext);\n+\n+\tif (p->pcre2_pattern) {\n+\t\tp->pcre2_match_data = pcre2_match_data_create_from_pattern(p->pcre2_pattern, NULL);\n+\t\tif (!p->pcre2_match_data)\n+\t\t\tdie(\"BUG: Couldn't allocate PCRE2 match data\");\n+\t} else {\n+\t\tpcre2_get_error_message(error, errbuf, sizeof(errbuf));\n+\t\tcompile_regexp_failed(p, (const char *)&errbuf);\n+\t}\n+\n+\tpcre2_config(PCRE2_CONFIG_JIT, &canjit);\n+\tif (canjit == 1) {\n+\t\tjitret = pcre2_jit_compile(p->pcre2_pattern, PCRE2_JIT_COMPLETE);\n+\t\tif (!jitret)\n+\t\t\tp->pcre2_jit_on = 1;\n+\t\telse\n+\t\t\tdie(\"BUG: Couldn't JIT the PCRE2 pattern '%s', got '%d'\\n\", p->pattern, jitret);\n+\t\tp->pcre2_jit_stack = pcre2_jit_stack_create(1, 1024 * 1024, NULL);\n+\t\tif (!p->pcre2_jit_stack)\n+\t\t\tdie(\"BUG: Couldn't allocate PCRE2 JIT stack\");\n+\t\tp->pcre2_match_context = pcre2_match_context_create(NULL);\n+\t\tif (!p->pcre2_jit_stack)\n+\t\t\tdie(\"BUG: Couldn't allocate PCRE2 match context\");\n+\t\tpcre2_jit_stack_assign(p->pcre2_match_context, NULL, p->pcre2_jit_stack);\n+\t}\n+}\n+\n+static int pcre2match(struct grep_pat *p, const char *line, const char *eol,\n+\t\tregmatch_t *match, int eflags)\n+{\n+\tint ret, flags = 0;\n+\tPCRE2_SIZE *ovector;\n+\n+\tif (eflags & REG_NOTBOL)\n+\t\tflags |= PCRE2_NOTBOL;\n+\n+\tif (p->pcre2_jit_on)\n+\t\tret = pcre2_jit_match(p->pcre2_pattern, (unsigned char *)line,\n+\t\t\t\t      eol - line, 0, flags, p->pcre2_match_data,\n+\t\t\t\t      NULL);\n+\telse\n+\t\tret = pcre2_match(p->pcre2_pattern, (unsigned char *)line,\n+\t\t\t\t  eol - line, 0, flags, p->pcre2_match_data,\n+\t\t\t\t  NULL);\n+\n+\tif (ret < 0 && ret != PCRE2_ERROR_NOMATCH)\n+\t\tdie(\"pcre_exec failed with error code %d\", ret);\n+\tif (ret > 0) {\n+\t\tovector = pcre2_get_ovector_pointer(p->pcre2_match_data);\n+\t\tret = 0;\n+\t\tmatch->rm_so = (int)ovector[0];\n+\t\tmatch->rm_eo = (int)ovector[1];\n+\t}\n+\n+\treturn ret;\n+}\n+\n+static void free_pcre2_pattern(struct grep_pat *p)\n+{\n+\tpcre2_compile_context_free(p->pcre2_ccontext);\n+\tpcre2_code_free(p->pcre2_pattern);\n+\tpcre2_match_data_free(p->pcre2_match_data);\n+\tpcre2_jit_stack_free(p->pcre2_jit_stack);\n+\tpcre2_match_context_free(p->pcre2_match_context);\n+}\n+#else /* !USE_LIBPCRE2 */\n+static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt)\n+{\n+\tdie(\"cannot use Perl-compatible regexes when not compiled with USE_LIBPCRE2\");\n+}\n+\n+static int pcre2match(struct grep_pat *p, const char *line, const char *eol,\n+\t\tregmatch_t *match, int eflags)\n+{\n+\treturn 1;\n+}\n+\n+static void free_pcre2_pattern(struct grep_pat *p)\n+{\n+}\n+#endif /* !USE_LIBPCRE2 */\n+\n static int is_fixed(const char *s, size_t len)\n {\n \tsize_t i;\n@@ -506,6 +642,11 @@ static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)\n \t\treturn;\n \t}\n \n+\tif (opt->pcre2) {\n+\t\tcompile_pcre2_pattern(p, opt);\n+\t\treturn;\n+\t}\n+\n \terr = regcomp(&p->regexp, p->pattern, opt->regflags);\n \tif (err) {\n \t\tchar errbuf[1024];\n@@ -860,6 +1001,8 @@ void free_grep_patterns(struct grep_opt *opt)\n \t\t\t\tkwsfree(p->kws);\n \t\t\telse if (p->pcre1_regexp)\n \t\t\t\tfree_pcre1_regexp(p);\n+\t\t\telse if (p->pcre2_pattern)\n+\t\t\t\tfree_pcre2_pattern(p);\n \t\t\telse\n \t\t\t\tregfree(&p->regexp);\n \t\t\tfree(p->pattern);\n@@ -940,6 +1083,8 @@ static int patmatch(struct grep_pat *p, char *line, char *eol,\n \t\thit = !fixmatch(p, line, eol, match);\n \telse if (p->pcre1_regexp)\n \t\thit = !pcre1match(p, line, eol, match, eflags);\n+\telse if (p->pcre2_pattern)\n+\t\thit = !pcre2match(p, line, eol, match, eflags);\n \telse\n \t\thit = !regexec_buf(&p->regexp, line, eol - line, 1, match,\n \t\t\t\t   eflags);\ndiff --git a/grep.h b/grep.h\nindex 29e20bf837..dd16b5fd53 100644\n--- a/grep.h\n+++ b/grep.h\n@@ -11,6 +11,16 @@ typedef int pcre;\n typedef int pcre_extra;\n typedef int pcre_jit_stack;\n #endif\n+#ifdef USE_LIBPCRE2\n+#define PCRE2_CODE_UNIT_WIDTH 8\n+#include <pcre2.h>\n+#else\n+typedef int pcre2_code;\n+typedef int pcre2_match_data;\n+typedef int pcre2_compile_context;\n+typedef int pcre2_match_context;\n+typedef int pcre2_jit_stack;\n+#endif\n #include \"kwset.h\"\n #include \"thread-utils.h\"\n #include \"userdiff.h\"\n@@ -54,6 +64,12 @@ struct grep_pat {\n \tpcre_extra *pcre1_extra_info;\n \tpcre_jit_stack *pcre1_jit_stack;\n \tconst unsigned char *pcre1_tables;\n+\tpcre2_code *pcre2_pattern;\n+\tpcre2_match_data *pcre2_match_data;\n+\tpcre2_compile_context *pcre2_ccontext;\n+\tpcre2_match_context *pcre2_match_context;\n+\tpcre2_jit_stack *pcre2_jit_stack;\n+\tint pcre2_jit_on;\n \tkwset_t kws;\n \tunsigned fixed:1;\n \tunsigned ignore_case:1;\n@@ -73,7 +89,9 @@ enum grep_pattern_type {\n \tGREP_PATTERN_TYPE_BRE,\n \tGREP_PATTERN_TYPE_ERE,\n \tGREP_PATTERN_TYPE_FIXED,\n-\tGREP_PATTERN_TYPE_PCRE1\n+\tGREP_PATTERN_TYPE_PCRE,\n+\tGREP_PATTERN_TYPE_PCRE1,\n+\tGREP_PATTERN_TYPE_PCRE2\n };\n \n struct grep_expr {\n@@ -117,6 +135,7 @@ struct grep_opt {\n \tint extended;\n \tint use_reflog_filter;\n \tint pcre1;\n+\tint pcre2;\n \tint relative;\n \tint pathname;\n \tint null_following_name;\ndiff --git a/revision.c b/revision.c\nindex 7a10a8570a..03a3a012de 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -1996,7 +1996,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg\n \t} else if (!strcmp(arg, \"--fixed-strings\") || !strcmp(arg, \"-F\")) {\n \t\trevs->grep_filter.pattern_type_option = GREP_PATTERN_TYPE_FIXED;\n \t} else if (!strcmp(arg, \"--perl-regexp\") || !strcmp(arg, \"-P\")) {\n-\t\trevs->grep_filter.pattern_type_option = GREP_PATTERN_TYPE_PCRE1;\n+\t\trevs->grep_filter.pattern_type_option = GREP_PATTERN_TYPE_PCRE;\n \t} else if (!strcmp(arg, \"--all-match\")) {\n \t\trevs->grep_filter.all_match = 1;\n \t} else if (!strcmp(arg, \"--invert-grep\")) {\ndiff --git a/t/README b/t/README\nindex a90cb62583..547b06e700 100644\n--- a/t/README\n+++ b/t/README\n@@ -808,6 +808,18 @@ use these, and \"test_set_prereq\" for how to define your own.\n    Git was compiled with support for PCRE. Wrap any tests\n    that use git-grep --perl-regexp or git-grep -P in these.\n \n+ - LIBPCRE1\n+\n+   Git was compiled with PCRE v1 support via\n+   USE_LIBPCRE=YesPlease. Wrap any PCRE using tests that for some\n+   reason need v1 of the PCRE library instead of v2 in these.\n+\n+ - LIBPCRE2\n+\n+   Git was compiled with PCRE v2 support via\n+   USE_LIBPCRE2=YesPlease. Wrap any PCRE using tests that for some\n+   reason need v2 of the PCRE library instead of v1 in these.\n+\n  - CASE_INSENSITIVE_FS\n \n    Test is run on a case insensitive file system.\ndiff --git a/t/perf/p7820-grep-engines.sh b/t/perf/p7820-grep-engines.sh\nindex 5ae42ceccc..70c5a5ca32 100755\n--- a/t/perf/p7820-grep-engines.sh\n+++ b/t/perf/p7820-grep-engines.sh\n@@ -7,7 +7,7 @@ test_description=\"Comparison of git-grep's regex engines\"\n test_perf_large_repo\n test_checkout_worktree\n \n-for engine in extended pcre1\n+for engine in extended pcre1 pcre2\n do\n \t# Patterns stolen from http://sljit.sourceforge.net/pcre.html\n \tfor pattern in \\\ndiff --git a/t/t7810-grep.sh b/t/t7810-grep.sh\nindex f929b447e9..bae7e524b9 100755\n--- a/t/t7810-grep.sh\n+++ b/t/t7810-grep.sh\n@@ -1063,6 +1063,16 @@ test_expect_success PCRE 'grep -P pattern' '\n \ttest_cmp expected actual\n '\n \n+test_expect_success LIBPCRE1 'grep libpcre1 pattern' '\n+\tgit -c grep.patternType=pcre1 grep \"\\p{Ps}.*?\\p{Pe}\" hello.c >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success LIBPCRE2 'grep libpcre2 pattern' '\n+\tgit -c grep.patternType=pcre2 grep \"\\p{Ps}.*?\\p{Pe}\" hello.c >actual &&\n+\ttest_cmp expected actual\n+'\n+\n test_expect_success 'grep pattern with grep.extendedRegexp=true' '\n \t>empty &&\n \ttest_must_fail git -c grep.extendedregexp=true \\\n@@ -1512,14 +1522,28 @@ test_expect_success 'grep does not report i-t-a and assume unchanged with -L' '\n \ttest_cmp expected actual\n '\n \n-test_expect_success PCRE \"grep with grep.patternType synonyms perl/pcre/pcre1\" '\n+test_expect_success PCRE \"grep with grep.patternType synonyms perl/pcre\" '\n \techo \"#include <stdio.h>\" >expected &&\n \tgit -c grep.patternType=perl  grep -h --no-line-number \"st(?=dio)\" >actual &&\n \ttest_cmp expected actual &&\n \tgit -c grep.patternType=pcre  grep -h --no-line-number \"st(?=dio)\" >actual &&\n-\ttest_cmp expected actual &&\n-\tgit -c grep.patternType=pcre1 grep -h --no-line-number \"st(?=dio)\" >actual &&\n \ttest_cmp expected actual\n '\n \n+test_expect_success LIBPCRE1 \"grep with grep.patternType=pcre1\" '\n+\techo \"#include <stdio.h>\" >expected &&\n+\tgit -c grep.patternType=pcre1 grep -h --no-line-number \"st(?=dio)\" >actual &&\n+\ttest_cmp expected actual &&\n+\ttest_must_fail git -c grep.patternType=pcre1 grep \"foo(?+bar)\" 2>error &&\n+\ttest_i18ngrep -q \"digit expected after\" error\n+'\n+\n+test_expect_success LIBPCRE2 \"grep with grep.patternType=pcre2\" '\n+\techo \"#include <stdio.h>\" >expected &&\n+\tgit -c grep.patternType=pcre2 grep -h --no-line-number \"st(?=dio)\" >actual &&\n+\ttest_cmp expected actual &&\n+\ttest_must_fail git -c grep.patternType=pcre2 grep \"foo(?+bar)\" 2>error &&\n+\ttest_i18ngrep -q \"digit expected after\" error\n+'\n+\n test_done\ndiff --git a/t/t7813-grep-icase-iso.sh b/t/t7813-grep-icase-iso.sh\nindex 701e08a8e5..e16570690c 100755\n--- a/t/t7813-grep-icase-iso.sh\n+++ b/t/t7813-grep-icase-iso.sh\n@@ -11,9 +11,12 @@ test_expect_success GETTEXT_ISO_LOCALE 'setup' '\n \texport LC_ALL\n '\n \n-test_expect_success GETTEXT_ISO_LOCALE,PCRE 'grep pcre string' '\n-\tgit grep --perl-regexp -i \"TILRAUN: H.ll� Heimur!\" &&\n-\tgit grep --perl-regexp -i \"TILRAUN: H.LL� HEIMUR!\"\n-'\n+for pcrev in 1 2\n+do\n+\ttest_expect_success GETTEXT_ISO_LOCALE,LIBPCRE$pcrev \"grep -i with i18n string using libpcre$pcrev\" \"\n+\t\tgit -c grep.patternType=pcre$pcrev grep -i \\\"TILRAUN: H.ll� Heimur!\\\" &&\n+\t\tgit -c grep.patternType=pcre$pcrev grep -i \\\"TILRAUN: H.LL� HEIMUR!\\\"\n+\t\"\n+done\n \n test_done\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex e5cfbcc36b..6f873de3e7 100644\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -1010,7 +1010,9 @@ esac\n ( COLUMNS=1 && test $COLUMNS = 1 ) && test_set_prereq COLUMNS_CAN_BE_1\n test -z \"$NO_PERL\" && test_set_prereq PERL\n test -z \"$NO_PYTHON\" && test_set_prereq PYTHON\n-test -n \"$USE_LIBPCRE1\" && test_set_prereq PCRE\n+test -n \"$USE_LIBPCRE1$USE_LIBPCRE2\" && test_set_prereq PCRE\n+test -n \"$USE_LIBPCRE1\" && test_set_prereq LIBPCRE1\n+test -n \"$USE_LIBPCRE2\" && test_set_prereq LIBPCRE2\n test -z \"$NO_GETTEXT\" && test_set_prereq GETTEXT\n \n # Can we rely on git's output in the C locale?\n-- \n2.11.0\n\n"}]}