Remove the need for "GREP_PATTERN_TYPE_UNSPECIFIED" in favor of having the users of the "pattern_type_option" member check whether that member is set or not. The "UNSPECIFIED" case was already handled implicitly in compile_regexp(), and we don't use this "enum" in a "switch" statement, so let's not explicitly name the "GREP_PATTERN_TYPE_UNSPECIFIED = 0" case. It is still important that "GREP_PATTERN_TYPE_BRE != 0", as can be seen in failing tests if the parsing for "basic" in parse_pattern_type_arg() is made to "return 0". Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@xxxxxxxxx> --- grep.c | 9 ++++++--- grep.h | 4 +--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/grep.c b/grep.c index a6712adbce7..914eb5dee9b 100644 --- a/grep.c +++ b/grep.c @@ -34,7 +34,7 @@ static const char *color_grep_slots[] = { static int parse_pattern_type_arg(const char *opt, const char *arg) { if (!strcmp(arg, "default")) - return GREP_PATTERN_TYPE_UNSPECIFIED; + return 0; else if (!strcmp(arg, "basic")) return GREP_PATTERN_TYPE_BRE; else if (!strcmp(arg, "extended")) @@ -50,8 +50,7 @@ define_list_config_array_extra(color_grep_slots, {"match"}); static void adjust_pattern_type(enum grep_pattern_type *pto, const int ero) { - if (*pto == GREP_PATTERN_TYPE_UNSPECIFIED) - *pto = ero ? GREP_PATTERN_TYPE_ERE : GREP_PATTERN_TYPE_BRE; + *pto = ero ? GREP_PATTERN_TYPE_ERE : GREP_PATTERN_TYPE_BRE; } /* @@ -69,12 +68,16 @@ int grep_config(const char *var, const char *value, void *cb) if (!strcmp(var, "grep.extendedregexp")) { ero = git_config_bool(var, value); + if (opt->pattern_type_option) + return 0; adjust_pattern_type(&opt->pattern_type_option, ero); return 0; } if (!strcmp(var, "grep.patterntype")) { opt->pattern_type_option = parse_pattern_type_arg(var, value); + if (opt->pattern_type_option) + return 0; if (ero == -1) return 0; adjust_pattern_type(&opt->pattern_type_option, ero); diff --git a/grep.h b/grep.h index 32ff4dad3de..e365b689287 100644 --- a/grep.h +++ b/grep.h @@ -94,8 +94,7 @@ enum grep_expr_node { }; enum grep_pattern_type { - GREP_PATTERN_TYPE_UNSPECIFIED = 0, - GREP_PATTERN_TYPE_BRE, + GREP_PATTERN_TYPE_BRE = 1, GREP_PATTERN_TYPE_ERE, GREP_PATTERN_TYPE_FIXED, GREP_PATTERN_TYPE_PCRE @@ -178,7 +177,6 @@ struct grep_opt { .relative = 1, \ .pathname = 1, \ .max_depth = -1, \ - .pattern_type_option = GREP_PATTERN_TYPE_UNSPECIFIED, \ .colors = { \ [GREP_COLOR_CONTEXT] = "", \ [GREP_COLOR_FILENAME] = "", \ -- 2.34.1.1250.g6a242c1e9ad