summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--builtin/grep.c10
-rw-r--r--grep.c69
-rw-r--r--grep.h3
-rw-r--r--revision.c2
4 files changed, 13 insertions, 71 deletions
diff --git a/builtin/grep.c b/builtin/grep.c
index 0ea124321b..942c4b2507 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -845,7 +845,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
int i;
int dummy;
int use_index = 1;
- int pattern_type_arg = GREP_PATTERN_TYPE_UNSPECIFIED;
int allow_revs;
struct option options[] = {
@@ -879,16 +878,16 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
N_("descend at most <depth> levels"), PARSE_OPT_NONEG,
NULL, 1 },
OPT_GROUP(""),
- OPT_SET_INT('E', "extended-regexp", &pattern_type_arg,
+ OPT_SET_INT('E', "extended-regexp", &opt.pattern_type_option,
N_("use extended POSIX regular expressions"),
GREP_PATTERN_TYPE_ERE),
- OPT_SET_INT('G', "basic-regexp", &pattern_type_arg,
+ OPT_SET_INT('G', "basic-regexp", &opt.pattern_type_option,
N_("use basic POSIX regular expressions (default)"),
GREP_PATTERN_TYPE_BRE),
- OPT_SET_INT('F', "fixed-strings", &pattern_type_arg,
+ OPT_SET_INT('F', "fixed-strings", &opt.pattern_type_option,
N_("interpret patterns as fixed strings"),
GREP_PATTERN_TYPE_FIXED),
- OPT_SET_INT('P', "perl-regexp", &pattern_type_arg,
+ OPT_SET_INT('P', "perl-regexp", &opt.pattern_type_option,
N_("use Perl-compatible regular expressions"),
GREP_PATTERN_TYPE_PCRE),
OPT_GROUP(""),
@@ -982,7 +981,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
argc = parse_options(argc, argv, prefix, options, grep_usage,
PARSE_OPT_KEEP_DASHDASH |
PARSE_OPT_STOP_AT_NON_OPTION);
- grep_commit_pattern_type(pattern_type_arg, &opt);
if (use_index && !startup_info->have_repository) {
int fallback = 0;
diff --git a/grep.c b/grep.c
index 60228a95a4..a8f503f55c 100644
--- a/grep.c
+++ b/grep.c
@@ -115,62 +115,6 @@ void grep_init(struct grep_opt *opt, struct repository *repo)
opt->header_tail = &opt->header_list;
}
-static void grep_set_pattern_type_option(enum grep_pattern_type pattern_type, struct grep_opt *opt)
-{
- /*
- * When committing to the pattern type by setting the relevant
- * fields in grep_opt it's generally not necessary to zero out
- * the fields we're not choosing, since they won't have been
- * set by anything. The extended_regexp_option field is the
- * only exception to this.
- *
- * This is because in the process of parsing grep.patternType
- * & grep.extendedRegexp we set opt->pattern_type_option and
- * opt->extended_regexp_option, respectively. We then
- * internally use opt->extended_regexp_option to see if we're
- * compiling an ERE. It must be unset if that's not actually
- * the case.
- */
- if (pattern_type != GREP_PATTERN_TYPE_ERE &&
- opt->extended_regexp_option)
- opt->extended_regexp_option = 0;
-
- switch (pattern_type) {
- case GREP_PATTERN_TYPE_UNSPECIFIED:
- /* fall through */
-
- case GREP_PATTERN_TYPE_BRE:
- break;
-
- case GREP_PATTERN_TYPE_ERE:
- opt->extended_regexp_option = 1;
- break;
-
- case GREP_PATTERN_TYPE_FIXED:
- opt->fixed = 1;
- break;
-
- case GREP_PATTERN_TYPE_PCRE:
- opt->pcre2 = 1;
- break;
- }
-}
-
-void grep_commit_pattern_type(enum grep_pattern_type pattern_type, struct grep_opt *opt)
-{
- if (pattern_type != GREP_PATTERN_TYPE_UNSPECIFIED)
- grep_set_pattern_type_option(pattern_type, opt);
- else if (opt->pattern_type_option != GREP_PATTERN_TYPE_UNSPECIFIED)
- grep_set_pattern_type_option(opt->pattern_type_option, opt);
- else if (opt->extended_regexp_option)
- /*
- * This branch *must* happen after setting from the
- * opt->pattern_type_option above, we don't want
- * grep.extendedRegexp to override grep.patternType!
- */
- grep_set_pattern_type_option(GREP_PATTERN_TYPE_ERE, opt);
-}
-
static struct grep_pat *create_grep_pat(const char *pat, size_t patlen,
const char *origin, int no,
enum grep_pat_token t,
@@ -488,11 +432,16 @@ static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
int err;
int regflags = REG_NEWLINE;
+ if (opt->pattern_type_option == GREP_PATTERN_TYPE_UNSPECIFIED)
+ opt->pattern_type_option = (opt->extended_regexp_option
+ ? GREP_PATTERN_TYPE_ERE
+ : GREP_PATTERN_TYPE_BRE);
+
p->word_regexp = opt->word_regexp;
p->ignore_case = opt->ignore_case;
- p->fixed = opt->fixed;
+ p->fixed = opt->pattern_type_option == GREP_PATTERN_TYPE_FIXED;
- if (!opt->pcre2 &&
+ if (opt->pattern_type_option != GREP_PATTERN_TYPE_PCRE &&
memchr(p->pattern, 0, p->patternlen))
die(_("given pattern contains NULL byte (via -f <file>). This is only supported with -P under PCRE v2"));
@@ -544,14 +493,14 @@ static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
return;
}
- if (opt->pcre2) {
+ if (opt->pattern_type_option == GREP_PATTERN_TYPE_PCRE) {
compile_pcre2_pattern(p, opt);
return;
}
if (p->ignore_case)
regflags |= REG_ICASE;
- if (opt->extended_regexp_option)
+ if (opt->pattern_type_option == GREP_PATTERN_TYPE_ERE)
regflags |= REG_EXTENDED;
err = regcomp(&p->regexp, p->pattern, regflags);
if (err) {
diff --git a/grep.h b/grep.h
index 89a2ce5113..c722d25ed9 100644
--- a/grep.h
+++ b/grep.h
@@ -143,7 +143,6 @@ struct grep_opt {
int unmatch_name_only;
int count;
int word_regexp;
- int fixed;
int all_match;
int no_body_match;
int body_hit;
@@ -154,7 +153,6 @@ struct grep_opt {
int allow_textconv;
int extended;
int use_reflog_filter;
- int pcre2;
int relative;
int pathname;
int null_following_name;
@@ -202,7 +200,6 @@ struct grep_opt {
int grep_config(const char *var, const char *value, void *);
void grep_init(struct grep_opt *, struct repository *repo);
-void grep_commit_pattern_type(enum grep_pattern_type, struct grep_opt *opt);
void append_grep_pat(struct grep_opt *opt, const char *pat, size_t patlen, const char *origin, int no, enum grep_pat_token t);
void append_grep_pattern(struct grep_opt *opt, const char *pat, const char *origin, int no, enum grep_pat_token t);
diff --git a/revision.c b/revision.c
index d6e0e2b23b..dd301e3014 100644
--- a/revision.c
+++ b/revision.c
@@ -2860,8 +2860,6 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
diff_setup_done(&revs->diffopt);
- grep_commit_pattern_type(GREP_PATTERN_TYPE_UNSPECIFIED,
- &revs->grep_filter);
if (!is_encoding_utf8(get_log_output_encoding()))
revs->grep_filter.ignore_locale = 1;
compile_grep_patterns(&revs->grep_filter);