Skip to content

Commit a67e281

Browse files
pcloudsgitster
authored andcommitted
grep: do not do external grep on skip-worktree entries
Skip-worktree entries are not on disk. We cannot use external grep in such cases. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7fce6e3 commit a67e281

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

builtin-grep.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,21 @@ static void grep_add_color(struct strbuf *sb, const char *escape_seq)
357357
strbuf_setlen(sb, sb->len - 1);
358358
}
359359

360+
static int has_skip_worktree_entry(struct grep_opt *opt, const char **paths)
361+
{
362+
int nr;
363+
for (nr = 0; nr < active_nr; nr++) {
364+
struct cache_entry *ce = active_cache[nr];
365+
if (!S_ISREG(ce->ce_mode))
366+
continue;
367+
if (!pathspec_matches(paths, ce->name, opt->max_depth))
368+
continue;
369+
if (ce_skip_worktree(ce))
370+
return 1;
371+
}
372+
return 0;
373+
}
374+
360375
static int external_grep(struct grep_opt *opt, const char **paths, int cached)
361376
{
362377
int i, nr, argc, hit, len, status;
@@ -365,7 +380,8 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached)
365380
char *argptr = randarg;
366381
struct grep_pat *p;
367382

368-
if (opt->extended || (opt->relative && opt->prefix_length))
383+
if (opt->extended || (opt->relative && opt->prefix_length)
384+
|| has_skip_worktree_entry(opt, paths))
369385
return -1;
370386
len = nr = 0;
371387
push_arg("grep");

0 commit comments

Comments
 (0)