git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 07/13] grep: make grep.patternType=[pcre|pcre1] a synonym for "perl"

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Apr 19, 2017, 22:40 UTC
Message-ID
<20170419224053.8920-8-avarab@gmail.com>
In-Reply-To
<20170419224053.8920-1-avarab@gmail.com>

Make the pattern types "pcre" & "pcre1" synonyms for the long-standing "perl" grep.patternType.

This change is part of a longer patch series to add pcre2 support to Git. It's nice to be able to performance test PCRE v1 v.s. v2 without having to recompile git, and doing that via grep.patternType makes sense.

However, just adding "pcre2" when we only have "perl" would be confusing, so start by adding a "pcre" & "pcre1" synonym.

In the future "perl" and "pcre" might be changed to default to "pcre2" instead of "pcre1", and depending on how Git is compiled the more specific "pcre1" or "pcre2" pattern types might produce an error.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 Documentation/config.txt |  9 +++++++++
 grep.c                   |  4 +++-
 t/t7810-grep.sh          | 10 ++++++++++
 3 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 475e874d51..5ef12d0694 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1624,6 +1624,15 @@ grep.patternType::
 	'fixed', or 'perl' will enable the `--basic-regexp`, `--extended-regexp`,
 	`--fixed-strings`, or `--perl-regexp` option accordingly, while the
 	value 'default' will return to the default matching behavior.
++
+The 'pcre' and 'pcre1' values are synonyms for 'perl'. The other
+values starting with 'pcre' are reserved for future use, e.g. if we'd
+like to use 'pcre2' for the PCRE v2 library.
++
+In the future 'perl' and 'pcre' might become synonyms for some other
+implementation or PCRE version, such as 'pcre2', while the more
+specific 'pcre1' & 'pcre2' might throw errors depending on whether git
+is compiled to include those libraries.
 
 grep.extendedRegexp::
 	If set to true, enable `--extended-regexp` option by default. This
diff --git a/grep.c b/grep.c
index 59ae7809f2..506545c0ee 100644
--- a/grep.c
+++ b/grep.c
@@ -60,7 +60,9 @@ static int parse_pattern_type_arg(const char *opt, const char *arg)
 		return GREP_PATTERN_TYPE_ERE;
 	else if (!strcmp(arg, "fixed"))
 		return GREP_PATTERN_TYPE_FIXED;
-	else if (!strcmp(arg, "perl"))
+	else if (!strcmp(arg, "perl") ||
+		 !strcmp(arg, "pcre") ||
+		 !strcmp(arg, "pcre1"))
 		return GREP_PATTERN_TYPE_PCRE;
 	die("bad %s argument: %s", opt, arg);
 }
diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh
index 8baed0f37d..0fb95c7438 100755
--- a/t/t7810-grep.sh
+++ b/t/t7810-grep.sh
@@ -1512,4 +1512,14 @@ test_expect_success 'grep does not report i-t-a and assume unchanged with -L' '
 	test_cmp expected actual
 '
 
+test_expect_success LIBPCRE "grep with grep.patternType synonyms perl/pcre/pcre1" '
+	echo "#include <stdio.h>" >expected &&
+	git -c grep.patternType=perl  grep -h --no-line-number "st(?=dio)" >actual &&
+	test_cmp expected actual &&
+	git -c grep.patternType=pcre  grep -h --no-line-number "st(?=dio)" >actual &&
+	test_cmp expected actual &&
+	git -c grep.patternType=pcre1 grep -h --no-line-number "st(?=dio)" >actual &&
+	test_cmp expected actual
+'
+
 test_done
-- 
2.11.0
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 10 of 14 in “PCRE v1 improvements & PCRE v2 support”
  1. 00/13 PCRE v1 improvements & PCRE v2 supportÆvar Arnfjörð Bjarmason, Apr 19, 2017
  2. 01/13 grep: remove redundant regflags assignment under PCREÆvar Arnfjörð Bjarmason, Apr 19, 2017
  3. 02/13 Makefile & configure: reword outdated comment about PCREÆvar Arnfjörð Bjarmason, Apr 19, 2017
  4. 03/13 grep: add a test for backreferences in PCRE patternsÆvar Arnfjörð Bjarmason, Apr 19, 2017
  5. 04/13 log: add exhaustive tests for pattern style options & configÆvar Arnfjörð Bjarmason, Apr 19, 2017
  6. 05/13 log: add -P as a synonym for --perl-regexpÆvar Arnfjörð Bjarmason, Apr 19, 2017
  7. 06/13 grep & rev-list doc: stop promising libpcre for --perl-regexpÆvar Arnfjörð Bjarmason, Apr 19, 2017
  8. 08/13 test-lib: rename the LIBPCRE prerequisite to PCREÆvar Arnfjörð Bjarmason, Apr 19, 2017
  9. 09/13 grep: change the internal PCRE macro names to be PCRE1Ævar Arnfjörð Bjarmason, Apr 19, 2017
  10. 07/13 grep: make grep.patternType=[pcre|pcre1] a synonym for "perl"Ævar Arnfjörð Bjarmason, Apr 19, 2017
  11. 10/13 grep: change the internal PCRE code & header names to be PCRE1Ævar Arnfjörð Bjarmason, Apr 19, 2017
  12. 11/13 perf: add a performance comparison test of grep -E and -PÆvar Arnfjörð Bjarmason, Apr 19, 2017
  13. 12/13 grep: add support for the PCRE v1 JIT APIÆvar Arnfjörð Bjarmason, Apr 19, 2017
  14. 13/13 grep: add support for PCRE v2Ævar Arnfjörð Bjarmason, Apr 19, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.