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

[PATCH v3 6/6] git-grep: Bail out when -P is used with -F or -E

From
Michał Kiedrowicz <michal.kiedrowicz@gmail.com>
Date
May 9, 2011, 21:52 UTC
Message-ID
<1304977928-7142-7-git-send-email-michal.kiedrowicz@gmail.com>
In-Reply-To
<1304977928-7142-1-git-send-email-michal.kiedrowicz@gmail.com>

This patch makes git-grep die() when -P is used on command line together with -E/--extended-regexp or -F/--fixed-strings.

This also makes it bail out when grep.extendedRegexp is enabled.

But `git grep -G -P pattern` and `git grep -E -G -P pattern` still work because -G and -E set opts.regflags during parse_options() and there is no way to detect `-G` or `-E -G`.

Signed-off-by: Michał Kiedrowicz <michal.kiedrowicz@gmail.com>
---
 builtin/grep.c  |    4 +++-
 t/t7810-grep.sh |   16 ++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletions(-)
diff --git a/builtin/grep.c b/builtin/grep.c
index 6831975..8f26026 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -925,9 +925,11 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 
 	if (!opt.pattern_list)
 		die(_("no pattern given."));
+	if (opt.regflags != REG_NEWLINE && opt.pcre)
+		die(_("cannot mix --extended-regexp and --perl-regexp"));
 	if (!opt.fixed && opt.ignore_case)
 		opt.regflags |= REG_ICASE;
-	if ((opt.regflags != REG_NEWLINE) && opt.fixed)
+	if ((opt.regflags != REG_NEWLINE || opt.pcre) && opt.fixed)
 		die(_("cannot mix --fixed-strings and regexp"));
 
 #ifndef NO_PTHREADS
diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh
index e845218..2a31eca 100755
--- a/t/t7810-grep.sh
+++ b/t/t7810-grep.sh
@@ -637,4 +637,20 @@ test_expect_success LIBPCRE 'grep -P -w pattern' '
 	test_cmp expected actual
 '
 
+test_expect_success LIBPCRE 'grep -P -F returns error' '
+	test_expect_code 128 git grep -P -F main
+'
+
+test_expect_success LIBPCRE 'grep -P -E returns error' '
+	test_expect_code 128 git grep -P -E main
+'
+
+test_expect_failure LIBPCRE 'grep -P -G returns error' '
+	test_expect_code 128 git grep -P -G main
+'
+
+test_expect_failure LIBPCRE 'grep -P -E -G returns error' '
+	test_expect_code 128 git grep -P -E -G main
+'
+
 test_done
-- 
1.7.3.4
Previous: Michał KiedrowiczNext: Junio C Hamano
Message 7 of 10 in “Add PCRE support to git-grep”
  1. 0/6 Add PCRE support to git-grepMichał Kiedrowicz, May 9, 2011
  2. 1/6 grep: Fix a typo in a commentMichał Kiedrowicz, May 9, 2011
  3. 2/6 grep: Extract compile_regexp_failed() from compile_regexp()Michał Kiedrowicz, May 9, 2011
  4. 3/6 git-grep: Learn PCREMichał Kiedrowicz, May 9, 2011
  5. 4/6 configure: Check for libpcreMichał Kiedrowicz, May 9, 2011
  6. 5/6 grep: Add basic testsMichał Kiedrowicz, May 9, 2011
  7. 6/6 git-grep: Bail out when -P is used with -F or -EMichał Kiedrowicz, May 9, 2011
  8. Junio C HamanoMay 10, 2011
  9. Michal KiedrowiczMay 10, 2011
  10. Junio C HamanoMay 10, 2011

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.