summaryrefslogtreecommitdiff
path: root/builtin/grep.c
diff options
context:
space:
mode:
authorStefan Beller <sbeller@google.com>2018-05-15 01:04:25 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-05-16 00:48:32 (GMT)
commitb2aa84c789a032c60b81d6ad68527e3a9076b99b (patch)
treefa87d4910690ad5e0c745e3a6c3e73a0f6a71952 /builtin/grep.c
parent3013dff8662eae06457fe6e5348dfe2270810ab2 (diff)
downloadgit-b2aa84c789a032c60b81d6ad68527e3a9076b99b.zip
git-b2aa84c789a032c60b81d6ad68527e3a9076b99b.tar.gz
git-b2aa84c789a032c60b81d6ad68527e3a9076b99b.tar.bz2
grep: handle corrupt index files early
Any other caller of 'repo_read_index' dies upon a negative return of it, so grep should, too. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/grep.c')
-rw-r--r--builtin/grep.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/builtin/grep.c b/builtin/grep.c
index 5a6cfe6..567565b 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -480,7 +480,8 @@ static int grep_cache(struct grep_opt *opt, struct repository *repo,
strbuf_addstr(&name, repo->submodule_prefix);
}
- repo_read_index(repo);
+ if (repo_read_index(repo) < 0)
+ die("index file corrupt");
for (nr = 0; nr < repo->index->cache_nr; nr++) {
const struct cache_entry *ce = repo->index->cache[nr];