@matheusbsbs / matheus-bagliano / commits / a67e281162
Fork 0

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 <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Dec 30, 2009 at 21:11 UTC a67e28116287ea84b162b22a5b69ec02ebd34023
1 file changed +17 -1
builtin-grep.c
+17 -1
@@ -357,6 +357,21 @@ static void grep_add_color(struct strbuf *sb, const char *escape_seq)
357 strbuf_setlen(sb, sb->len - 1);
358 }
359
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 +
375 static int external_grep(struct grep_opt *opt, const char **paths, int cached)
376 {
377 int i, nr, argc, hit, len, status;
@@ -365,7 +380,8 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached)
380 char *argptr = randarg;
381 struct grep_pat *p;
382
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))
385 return -1;
386 len = nr = 0;
387 push_arg("grep");