Code

Merge branch 'jc/grep-lookahead'
[git.git] / builtin-grep.c
index 12833733dba9c2f455d78bdcad0b0c4c6ed81da0..da854fa94f5cc159ea93156ba4c87973ee15cae9 100644 (file)
@@ -182,8 +182,6 @@ static int grep_file(struct grep_opt *opt, const char *filename)
                        error("'%s': %s", filename, strerror(errno));
                return 0;
        }
-       if (!st.st_size)
-               return 0; /* empty file -- no grep hit */
        if (!S_ISREG(st.st_mode))
                return 0;
        sz = xsize_t(st.st_size);
@@ -198,6 +196,7 @@ static int grep_file(struct grep_opt *opt, const char *filename)
                return 0;
        }
        close(i);
+       data[sz] = 0;
        if (opt->relative && opt->prefix_length)
                filename = quote_path_relative(filename, -1, &buf, opt->prefix);
        i = grep_buffer(opt, filename, data, sz);
@@ -223,7 +222,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);