summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2012-10-03 14:47:48 -0700
committerJunio C Hamano <gitster@pobox.com>2012-10-09 23:21:29 -0700
commitc5c31d3381d11903c01d51aff4437fe9f76d0268 (patch)
tree682b0c58edeca691a127934e7d22063208ab3b10 /builtin
parent7687a0541e0a6d86c5005d84057321368181c1b5 (diff)
downloadgit-c5c31d3381d11903c01d51aff4437fe9f76d0268.tar.gz
grep: move pattern-type bits support to top-level grep.[ch]
Switching between -E/-G/-P/-F correctly needs a lot more than just flipping opt->regflags bit these days, and we have a nice helper function buried in builtin/grep.c for the sole use of "git grep". Extract it so that "log --grep" family can also use it. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/grep.c40
1 files changed, 1 insertions, 39 deletions
diff --git a/builtin/grep.c b/builtin/grep.c
index b63a9f8368..c296e6f99e 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -261,38 +261,6 @@ static int wait_all(void)
}
#endif
-static void grep_pattern_type_options(const int pattern_type, struct grep_opt *opt)
-{
- switch (pattern_type) {
- case GREP_PATTERN_TYPE_UNSPECIFIED:
- /* fall through */
-
- case GREP_PATTERN_TYPE_BRE:
- opt->fixed = 0;
- opt->pcre = 0;
- opt->regflags &= ~REG_EXTENDED;
- break;
-
- case GREP_PATTERN_TYPE_ERE:
- opt->fixed = 0;
- opt->pcre = 0;
- opt->regflags |= REG_EXTENDED;
- break;
-
- case GREP_PATTERN_TYPE_FIXED:
- opt->fixed = 1;
- opt->pcre = 0;
- opt->regflags &= ~REG_EXTENDED;
- break;
-
- case GREP_PATTERN_TYPE_PCRE:
- opt->fixed = 0;
- opt->pcre = 1;
- opt->regflags &= ~REG_EXTENDED;
- break;
- }
-}
-
static int grep_cmd_config(const char *var, const char *value, void *cb)
{
int st = grep_config(var, value, cb);
@@ -798,13 +766,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
PARSE_OPT_KEEP_DASHDASH |
PARSE_OPT_STOP_AT_NON_OPTION |
PARSE_OPT_NO_INTERNAL_HELP);
-
- if (pattern_type_arg != GREP_PATTERN_TYPE_UNSPECIFIED)
- grep_pattern_type_options(pattern_type_arg, &opt);
- else if (opt.pattern_type_option != GREP_PATTERN_TYPE_UNSPECIFIED)
- grep_pattern_type_options(opt.pattern_type_option, &opt);
- else if (opt.extended_regexp_option)
- grep_pattern_type_options(GREP_PATTERN_TYPE_ERE, &opt);
+ grep_commit_pattern_type(pattern_type_arg, &opt);
if (use_index && !startup_info->have_repository)
/* die the same way as if we did it at the beginning */