]> git.ipfire.org Git - thirdparty/git.git/blobdiff - grep.c
grep tests: move binary pattern tests into their own file
[thirdparty/git.git] / grep.c
diff --git a/grep.c b/grep.c
index 0d50598acda6f1c41951d1d656ea701114473239..4e8d0645a8328889b7c9f3eb54cb5cdd61e8328f 100644 (file)
--- a/grep.c
+++ b/grep.c
@@ -388,11 +388,11 @@ static void compile_pcre1_regexp(struct grep_pat *p, const struct grep_opt *opt)
        int options = PCRE_MULTILINE;
 
        if (opt->ignore_case) {
-               if (has_non_ascii(p->pattern))
+               if (!opt->ignore_locale && has_non_ascii(p->pattern))
                        p->pcre1_tables = pcre_maketables();
                options |= PCRE_CASELESS;
        }
-       if (is_utf8_locale() && has_non_ascii(p->pattern))
+       if (!opt->ignore_locale && is_utf8_locale() && has_non_ascii(p->pattern))
                options |= PCRE_UTF8;
 
        p->pcre1_regexp = pcre_compile(p->pattern, options, &error, &erroffset,
@@ -498,14 +498,14 @@ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt
        p->pcre2_compile_context = NULL;
 
        if (opt->ignore_case) {
-               if (has_non_ascii(p->pattern)) {
+               if (!opt->ignore_locale && has_non_ascii(p->pattern)) {
                        character_tables = pcre2_maketables(NULL);
                        p->pcre2_compile_context = pcre2_compile_context_create(NULL);
                        pcre2_set_character_tables(p->pcre2_compile_context, character_tables);
                }
                options |= PCRE2_CASELESS;
        }
-       if (is_utf8_locale() && has_non_ascii(p->pattern))
+       if (!opt->ignore_locale && is_utf8_locale() && has_non_ascii(p->pattern))
                options |= PCRE2_UTF;
 
        p->pcre2_pattern = pcre2_compile((PCRE2_SPTR)p->pattern,
@@ -650,13 +650,11 @@ static void compile_fixed_regexp(struct grep_pat *p, struct grep_opt *opt)
 
 static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
 {
-       int ascii_only;
        int err;
        int regflags = REG_NEWLINE;
 
        p->word_regexp = opt->word_regexp;
        p->ignore_case = opt->ignore_case;
-       ascii_only     = !has_non_ascii(p->pattern);
 
        /*
         * Even when -F (fixed) asks us to do a non-regexp search, we
@@ -673,7 +671,7 @@ static void compile_regexp(struct grep_pat *p, struct grep_opt *opt)
        if (opt->fixed ||
            has_null(p->pattern, p->patternlen) ||
            is_fixed(p->pattern, p->patternlen))
-               p->fixed = !p->ignore_case || ascii_only;
+               p->fixed = !p->ignore_case || !has_non_ascii(p->pattern);
 
        if (p->fixed) {
                p->kws = kwsalloc(p->ignore_case ? tolower_trans_tbl : NULL);
@@ -1780,6 +1778,10 @@ static int grep_source_1(struct grep_opt *opt, struct grep_source *gs, int colle
        enum grep_context ctx = GREP_CONTEXT_HEAD;
        xdemitconf_t xecfg;
 
+       if (!opt->status_only && gs->name == NULL)
+               BUG("grep call which could print a name requires "
+                   "grep_source.name be non-NULL");
+
        if (!opt->output)
                opt->output = std_output;