]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin/grep.c
Merge branch 'ab/grep-patterntype'
[thirdparty/git.git] / builtin / grep.c
index 88144f06300b539dfe156cd6d76cd5b8a69e9369..f1a924eadebf45ec6bcc32c22ad89c0716a5be24 100644 (file)
@@ -26,6 +26,8 @@
 #include "object-store.h"
 #include "packfile.h"
 
+static const char *grep_prefix;
+
 static char const * const grep_usage[] = {
        N_("git grep [<options>] [-e] <pattern> [<rev>...] [[--] <path>...]"),
        NULL
@@ -284,7 +286,7 @@ static int wait_all(void)
 static int grep_cmd_config(const char *var, const char *value, void *cb)
 {
        int st = grep_config(var, value, cb);
-       if (git_color_default_config(var, value, cb) < 0)
+       if (git_color_default_config(var, value, NULL) < 0)
                st = -1;
 
        if (!strcmp(var, "grep.threads")) {
@@ -315,11 +317,11 @@ static void grep_source_name(struct grep_opt *opt, const char *filename,
        strbuf_reset(out);
 
        if (opt->null_following_name) {
-               if (opt->relative && opt->prefix_length) {
+               if (opt->relative && grep_prefix) {
                        struct strbuf rel_buf = STRBUF_INIT;
                        const char *rel_name =
                                relative_path(filename + tree_name_len,
-                                             opt->prefix, &rel_buf);
+                                             grep_prefix, &rel_buf);
 
                        if (tree_name_len)
                                strbuf_add(out, filename, tree_name_len);
@@ -332,8 +334,8 @@ static void grep_source_name(struct grep_opt *opt, const char *filename,
                return;
        }
 
-       if (opt->relative && opt->prefix_length)
-               quote_path(filename + tree_name_len, opt->prefix, out, 0);
+       if (opt->relative && grep_prefix)
+               quote_path(filename + tree_name_len, grep_prefix, out, 0);
        else
                quote_c_style(filename + tree_name_len, out, NULL, 0);
 
@@ -843,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[] = {
@@ -877,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(""),
@@ -962,9 +963,10 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
                           PARSE_OPT_NOCOMPLETE),
                OPT_END()
        };
+       grep_prefix = prefix;
 
-       git_config(grep_cmd_config, NULL);
-       grep_init(&opt, the_repository, prefix);
+       grep_init(&opt, the_repository);
+       git_config(grep_cmd_config, &opt);
 
        /*
         * If there is no -- then the paths must exist in the working
@@ -979,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;