grep: remove redundant and verbose re-assignments to 0
[gitweb.git] / grep.c
diff --git a/grep.c b/grep.c
index d7ef21358ea7f592dffff98884eb34169e097880..7fcdaa0753b7a9678e5eb4d0ad8aff9728bd6ea9 100644 (file)
--- a/grep.c
+++ b/grep.c
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "grep.h"
 #include "userdiff.h"
 #include "xdiff-interface.h"
@@ -37,7 +38,6 @@ void init_grep_defaults(void)
        opt->regflags = REG_NEWLINE;
        opt->max_depth = -1;
        opt->pattern_type_option = GREP_PATTERN_TYPE_UNSPECIFIED;
-       opt->extended_regexp_option = 0;
        color_set(opt->color_context, "");
        color_set(opt->color_filename, "");
        color_set(opt->color_function, "");
@@ -78,10 +78,7 @@ int grep_config(const char *var, const char *value, void *cb)
                return -1;
 
        if (!strcmp(var, "grep.extendedregexp")) {
-               if (git_config_bool(var, value))
-                       opt->extended_regexp_option = 1;
-               else
-                       opt->extended_regexp_option = 0;
+               opt->extended_regexp_option = git_config_bool(var, value);
                return 0;
        }
 
@@ -177,28 +174,18 @@ static void grep_set_pattern_type_option(enum grep_pattern_type pattern_type, st
                /* fall through */
 
        case GREP_PATTERN_TYPE_BRE:
-               opt->fixed = 0;
-               opt->pcre1 = 0;
-               opt->pcre2 = 0;
                break;
 
        case GREP_PATTERN_TYPE_ERE:
-               opt->fixed = 0;
-               opt->pcre1 = 0;
-               opt->pcre2 = 0;
                opt->regflags |= REG_EXTENDED;
                break;
 
        case GREP_PATTERN_TYPE_FIXED:
                opt->fixed = 1;
-               opt->pcre1 = 0;
-               opt->pcre2 = 0;
                break;
 
        case GREP_PATTERN_TYPE_PCRE:
-               opt->fixed = 0;
 #ifdef USE_LIBPCRE2
-               opt->pcre1 = 0;
                opt->pcre2 = 1;
 #else
                /*
@@ -208,7 +195,6 @@ static void grep_set_pattern_type_option(enum grep_pattern_type pattern_type, st
                 * "cannot use Perl-compatible regexes[...]".
                 */
                opt->pcre1 = 1;
-               opt->pcre2 = 0;
 #endif
                break;
        }
@@ -508,7 +494,7 @@ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt
                if (!p->pcre2_jit_stack)
                        die("Couldn't allocate PCRE2 JIT stack");
                p->pcre2_match_context = pcre2_match_context_create(NULL);
-               if (!p->pcre2_jit_stack)
+               if (!p->pcre2_match_context)
                        die("Couldn't allocate PCRE2 match context");
                pcre2_jit_stack_assign(p->pcre2_match_context, NULL, p->pcre2_jit_stack);
        } else if (p->pcre2_jit_on != 0) {
@@ -629,8 +615,6 @@ static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
            has_null(p->pattern, p->patternlen) ||
            is_fixed(p->pattern, p->patternlen))
                p->fixed = !icase || ascii_only;
-       else
-               p->fixed = 0;
 
        if (p->fixed) {
                p->kws = kwsalloc(icase ? tolower_trans_tbl : NULL);
@@ -1939,12 +1923,9 @@ void grep_source_init(struct grep_source *gs, enum grep_source_type type,
 
 void grep_source_clear(struct grep_source *gs)
 {
-       free(gs->name);
-       gs->name = NULL;
-       free(gs->path);
-       gs->path = NULL;
-       free(gs->identifier);
-       gs->identifier = NULL;
+       FREE_AND_NULL(gs->name);
+       FREE_AND_NULL(gs->path);
+       FREE_AND_NULL(gs->identifier);
        grep_source_clear_data(gs);
 }
 
@@ -1954,8 +1935,7 @@ void grep_source_clear_data(struct grep_source *gs)
        case GREP_SOURCE_FILE:
        case GREP_SOURCE_OID:
        case GREP_SOURCE_SUBMODULE:
-               free(gs->buf);
-               gs->buf = NULL;
+               FREE_AND_NULL(gs->buf);
                gs->size = 0;
                break;
        case GREP_SOURCE_BUF: