summaryrefslogtreecommitdiff
path: root/builtin/grep.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2012-10-09 23:17:50 (GMT)
committerJunio C Hamano <gitster@pobox.com>2012-10-09 23:17:50 (GMT)
commit7687a0541e0a6d86c5005d84057321368181c1b5 (patch)
tree159dbf096726f174631cff9b27ec9fc834e71665 /builtin/grep.c
parent15fabd1bbd4c997d0edb2249295e2717bc18b6c7 (diff)
downloadgit-7687a0541e0a6d86c5005d84057321368181c1b5.zip
git-7687a0541e0a6d86c5005d84057321368181c1b5.tar.gz
git-7687a0541e0a6d86c5005d84057321368181c1b5.tar.bz2
grep: move the configuration parsing logic to grep.[ch]
The configuration handling is a library-ish part of this program, that is not specific to "git grep" command. It should be reusable by "log" and others. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/grep.c')
-rw-r--r--builtin/grep.c131
1 files changed, 0 insertions, 131 deletions
diff --git a/builtin/grep.c b/builtin/grep.c
index 83232c9..b63a9f8 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -261,21 +261,6 @@ static int wait_all(void)
}
#endif
-static int parse_pattern_type_arg(const char *opt, const char *arg)
-{
- if (!strcmp(arg, "default"))
- return GREP_PATTERN_TYPE_UNSPECIFIED;
- else if (!strcmp(arg, "basic"))
- return GREP_PATTERN_TYPE_BRE;
- else if (!strcmp(arg, "extended"))
- return GREP_PATTERN_TYPE_ERE;
- else if (!strcmp(arg, "fixed"))
- return GREP_PATTERN_TYPE_FIXED;
- else if (!strcmp(arg, "perl"))
- return GREP_PATTERN_TYPE_PCRE;
- die("bad %s argument: %s", opt, arg);
-}
-
static void grep_pattern_type_options(const int pattern_type, struct grep_opt *opt)
{
switch (pattern_type) {
@@ -308,122 +293,6 @@ static void grep_pattern_type_options(const int pattern_type, struct grep_opt *o
}
}
-static struct grep_opt grep_defaults;
-
-/*
- * Initialize the grep_defaults template with hardcoded defaults.
- * We could let the compiler do this, but without C99 initializers
- * the code gets unwieldy and unreadable, so...
- */
-static void init_grep_defaults(void)
-{
- struct grep_opt *opt = &grep_defaults;
-
- memset(opt, 0, sizeof(*opt));
- opt->relative = 1;
- opt->pathname = 1;
- opt->regflags = REG_NEWLINE;
- opt->max_depth = -1;
- opt->pattern_type_option = GREP_PATTERN_TYPE_UNSPECIFIED;
- opt->extended_regexp_option = 0;
- strcpy(opt->color_context, "");
- strcpy(opt->color_filename, "");
- strcpy(opt->color_function, "");
- strcpy(opt->color_lineno, "");
- strcpy(opt->color_match, GIT_COLOR_BOLD_RED);
- strcpy(opt->color_selected, "");
- strcpy(opt->color_sep, GIT_COLOR_CYAN);
- opt->color = -1;
-}
-
-/*
- * Read the configuration file once and store it in
- * the grep_defaults template.
- */
-static int grep_config(const char *var, const char *value, void *cb)
-{
- struct grep_opt *opt = &grep_defaults;
- char *color = NULL;
-
- if (userdiff_config(var, value) < 0)
- return -1;
-
- if (!strcmp(var, "grep.extendedregexp")) {
- if (git_config_bool(var, value))
- opt->extended_regexp_option = 1;
- else
- opt->extended_regexp_option = 0;
- return 0;
- }
-
- if (!strcmp(var, "grep.patterntype")) {
- opt->pattern_type_option = parse_pattern_type_arg(var, value);
- return 0;
- }
-
- if (!strcmp(var, "grep.linenumber")) {
- opt->linenum = git_config_bool(var, value);
- return 0;
- }
-
- if (!strcmp(var, "color.grep"))
- opt->color = git_config_colorbool(var, value);
- else if (!strcmp(var, "color.grep.context"))
- color = opt->color_context;
- else if (!strcmp(var, "color.grep.filename"))
- color = opt->color_filename;
- else if (!strcmp(var, "color.grep.function"))
- color = opt->color_function;
- else if (!strcmp(var, "color.grep.linenumber"))
- color = opt->color_lineno;
- else if (!strcmp(var, "color.grep.match"))
- color = opt->color_match;
- else if (!strcmp(var, "color.grep.selected"))
- color = opt->color_selected;
- else if (!strcmp(var, "color.grep.separator"))
- color = opt->color_sep;
-
- if (color) {
- if (!value)
- return config_error_nonbool(var);
- color_parse(value, var, color);
- }
- return 0;
-}
-
-/*
- * Initialize one instance of grep_opt and copy the
- * default values from the template we read the configuration
- * information in an earlier call to git_config(grep_config).
- */
-static void grep_init(struct grep_opt *opt, const char *prefix)
-{
- struct grep_opt *def = &grep_defaults;
-
- memset(opt, 0, sizeof(*opt));
- opt->prefix = prefix;
- opt->prefix_length = (prefix && *prefix) ? strlen(prefix) : 0;
- opt->pattern_tail = &opt->pattern_list;
- opt->header_tail = &opt->header_list;
-
- opt->color = def->color;
- opt->extended_regexp_option = def->extended_regexp_option;
- opt->pattern_type_option = def->pattern_type_option;
- opt->linenum = def->linenum;
- opt->max_depth = def->max_depth;
- opt->pathname = def->pathname;
- opt->regflags = def->regflags;
- opt->relative = def->relative;
-
- strcpy(opt->color_context, def->color_context);
- strcpy(opt->color_filename, def->color_filename);
- strcpy(opt->color_function, def->color_function);
- strcpy(opt->color_lineno, def->color_lineno);
- strcpy(opt->color_match, def->color_match);
- strcpy(opt->color_selected, def->color_selected);
- strcpy(opt->color_sep, def->color_sep);
-}
-
static int grep_cmd_config(const char *var, const char *value, void *cb)
{
int st = grep_config(var, value, cb);