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

[PATCH v2 6/7] log --grep: accept --basic-regexp and --perl-regexp

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 10, 2012, 07:55 UTC
Message-ID
<1349855714-17008-7-git-send-email-gitster@pobox.com>
In-Reply-To
<1349855714-17008-1-git-send-email-gitster@pobox.com>

When we added the "--perl-regexp" option (or "-P") to "git grep", we should have done the same for the commands in the "git log" family, but somehow we forgot to do so. This corrects it, but we will reserve the short-and-sweet "-P" option for something else for now.

Also introduce the "--basic-regexp" option for completeness, so that the "last one wins" principle can be used to defeat an earlier -E option, e.g. "git log -E --basic-regexp --grep='<bre>'". Note that it cannot have the short "-G" option as the option is to grep in the patch text in the context of "log" family.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 Documentation/rev-list-options.txt | 10 ++++++++++
 revision.c                         |  4 ++++
 2 files changed, 14 insertions(+)
diff --git a/Documentation/rev-list-options.txt b/Documentation/rev-list-options.txt
index ee49743..1ec14a0 100644
--- a/Documentation/rev-list-options.txt
+++ b/Documentation/rev-list-options.txt
@@ -79,6 +79,11 @@ if it is part of the log message.
 
 	Match the regexp limiting patterns without regard to letters case.
 
+--basic-regexp::
+
+	Consider the limiting patterns to be basic regular expressions;
+	this is the default.
+
 -E::
 --extended-regexp::
 
@@ -91,6 +96,11 @@ if it is part of the log message.
 	Consider the limiting patterns to be fixed strings (don't interpret
 	pattern as a regular expression).
 
+--perl-regexp::
+
+	Consider the limiting patterns to be Perl-compatible regexp.
+	Requires libpcre to be compiled in.
+
 --remove-empty::
 
 	Stop when a given path disappears from the tree.
diff --git a/revision.c b/revision.c
index 68545c8..d7d621c 100644
--- a/revision.c
+++ b/revision.c
@@ -1603,6 +1603,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 		return argcount;
 	} else if (!strcmp(arg, "--grep-debug")) {
 		revs->grep_filter.debug = 1;
+	} else if (!strcmp(arg, "--basic-regexp")) {
+		grep_set_pattern_type_option(GREP_PATTERN_TYPE_BRE, &revs->grep_filter);
 	} else if (!strcmp(arg, "--extended-regexp") || !strcmp(arg, "-E")) {
 		grep_set_pattern_type_option(GREP_PATTERN_TYPE_ERE, &revs->grep_filter);
 	} else if (!strcmp(arg, "--regexp-ignore-case") || !strcmp(arg, "-i")) {
@@ -1610,6 +1612,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
 		DIFF_OPT_SET(&revs->diffopt, PICKAXE_IGNORE_CASE);
 	} else if (!strcmp(arg, "--fixed-strings") || !strcmp(arg, "-F")) {
 		grep_set_pattern_type_option(GREP_PATTERN_TYPE_FIXED, &revs->grep_filter);
+	} else if (!strcmp(arg, "--perl-regexp")) {
+		grep_set_pattern_type_option(GREP_PATTERN_TYPE_PCRE, &revs->grep_filter);
 	} else if (!strcmp(arg, "--all-match")) {
 		revs->grep_filter.all_match = 1;
 	} else if ((argcount = parse_long_opt("encoding", argv, &optarg))) {
-- 
1.8.0.rc1.76.g5a375e6
Previous: Junio C HamanoNext: Junio C Hamano
Message 7 of 11 in “Tying loose ends on grep-pcre”
  1. 0/7 Tying loose ends on grep-pcreJunio C Hamano, Oct 10, 2012
  2. 1/7 builtin/grep.c: make configuration callback more reusableJunio C Hamano, Oct 10, 2012
  3. 2/7 grep: move the configuration parsing logic to grep.[ch]Junio C Hamano, Oct 10, 2012
  4. 3/7 grep: move pattern-type bits support to top-level grep.[ch]Junio C Hamano, Oct 10, 2012
  5. 4/7 revisions: initialize revs->grep_filter using grep_init()Junio C Hamano, Oct 10, 2012
  6. 5/7 log --grep: use the same helper to set -E/-F options as "git grep"Junio C Hamano, Oct 10, 2012
  7. 6/7 log --grep: accept --basic-regexp and --perl-regexpJunio C Hamano, Oct 10, 2012
  8. 7/7 log: honor grep.* configurationJunio C Hamano, Oct 10, 2012
  9. Michael HaggertyOct 10, 2012
  10. Junio C HamanoOct 10, 2012
  11. Michael HaggertyOct 11, 2012

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.