]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin/grep.c
Merge branch 'en/ort-perf-batch-9'
[thirdparty/git.git] / builtin / grep.c
index e348e6bb3264693a88db5da4cd8f9e43a48a4023..5de725f904419e3db520cc9bedbfd38808b132f2 100644 (file)
@@ -211,7 +211,7 @@ static void start_threads(struct grep_opt *opt)
                strbuf_init(&todo[i].out, 0);
        }
 
-       threads = xcalloc(num_threads, sizeof(*threads));
+       CALLOC_ARRAY(threads, num_threads);
        for (i = 0; i < num_threads; i++) {
                int err;
                struct grep_opt *o = grep_opt_dup(opt);
@@ -506,6 +506,10 @@ static int grep_cache(struct grep_opt *opt,
 
        for (nr = 0; nr < repo->index->cache_nr; nr++) {
                const struct cache_entry *ce = repo->index->cache[nr];
+
+               if (!cached && ce_skip_worktree(ce))
+                       continue;
+
                strbuf_setlen(&name, name_base_len);
                strbuf_addstr(&name, ce->name);
 
@@ -518,8 +522,7 @@ static int grep_cache(struct grep_opt *opt,
                         * cache entry are identical, even if worktree file has
                         * been modified, so use cache version instead
                         */
-                       if (cached || (ce->ce_flags & CE_VALID) ||
-                           ce_skip_worktree(ce)) {
+                       if (cached || (ce->ce_flags & CE_VALID)) {
                                if (ce_stage(ce) || ce_intent_to_add(ce))
                                        continue;
                                hit |= grep_oid(opt, &ce->oid, name.buf,
@@ -1178,6 +1181,5 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
                run_pager(&opt, prefix);
        clear_pathspec(&pathspec);
        free_grep_patterns(&opt);
-       grep_destroy();
        return !hit;
 }