Skip to content

Commit

Permalink
grep: do not do external grep on skip-worktree entries
Browse files Browse the repository at this point in the history
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 <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Nguyễn Thái Ngọc Duy authored and Junio C Hamano committed Dec 31, 2009
1 parent 7fce6e3 commit a67e281
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion builtin-grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,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;
Expand All @@ -365,7 +380,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");
Expand Down

0 comments on commit a67e281

Please sign in to comment.