]> Kevux Git Server - rit/commitdiff
grep --no-index: honor pathspecs correctly
authorJunio C Hamano <gitster@pobox.com>
Wed, 16 Feb 2011 22:39:00 +0000 (14:39 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 16 Feb 2011 22:39:00 +0000 (14:39 -0800)
Even though fill_directory() takes pathspec, the returned set of paths
is not guaranteed to be free of paths outside the pathspec. Perhaps we
would need to change that, but the current API is that the caller needs
to further filter them.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/grep.c

index c3af876..5afee2f 100644 (file)
@@ -626,6 +626,10 @@ static int grep_directory(struct grep_opt *opt, const struct pathspec *pathspec)
 
        fill_directory(&dir, pathspec->raw);
        for (i = 0; i < dir.nr; i++) {
+               const char *name = dir.entries[i]->name;
+               int namelen = strlen(name);
+               if (!match_pathspec_depth(pathspec, name, namelen, 0, NULL))
+                       continue;
                hit |= grep_file(opt, dir.entries[i]->name);
                if (hit && opt->status_only)
                        break;