Code

Merge branch 'maint'
[git.git] / builtin-grep.c
index c7d74fbb7fe26840d4084ad3fef2c8fd4674df6e..cea973ba6bafff69b72db0923e5b583dc0a3f8bc 100644 (file)
@@ -221,6 +221,7 @@ static int exec_grep(int argc, const char **argv)
        int status;
 
        argv[argc] = NULL;
+       trace_argv_printf(argv, "trace: grep:");
        pid = fork();
        if (pid < 0)
                return pid;
@@ -346,6 +347,21 @@ static void grep_add_color(struct strbuf *sb, const char *escape_seq)
                strbuf_setlen(sb, sb->len - 1);
 }
 
+static int has_skip_worktree_entry(struct grep_opt *opt, const char **paths)
+{
+       int nr;
+       for (nr = 0; nr < active_nr; nr++) {
+               struct cache_entry *ce = active_cache[nr];
+               if (!S_ISREG(ce->ce_mode))
+                       continue;
+               if (!pathspec_matches(paths, ce->name, opt->max_depth))
+                       continue;
+               if (ce_skip_worktree(ce))
+                       return 1;
+       }
+       return 0;
+}
+
 static int external_grep(struct grep_opt *opt, const char **paths, int cached)
 {
        int i, nr, argc, hit, len, status;
@@ -354,7 +370,8 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached)
        char *argptr = randarg;
        struct grep_pat *p;
 
-       if (opt->extended || (opt->relative && opt->prefix_length))
+       if (opt->extended || (opt->relative && opt->prefix_length)
+           || has_skip_worktree_entry(opt, paths))
                return -1;
        len = nr = 0;
        push_arg("grep");
@@ -511,7 +528,7 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached,
                 * are identical, even if worktree file has been modified, so use
                 * cache version instead
                 */
-               if (cached || (ce->ce_flags & CE_VALID)) {
+               if (cached || (ce->ce_flags & CE_VALID) || ce_skip_worktree(ce)) {
                        if (ce_stage(ce))
                                continue;
                        hit |= grep_sha1(opt, ce->sha1, ce->name, 0);