[PATCH] show-diff.c: check unreadbale blob.

This patch fixes show-diff to detect unreadable blob and warn
instead of going ahead and crashing.

Signed-off-by: Junio C Hamano <junkio@cox.net>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
maint
Junio C Hamano 2005-04-18 15:07:24 -07:00 committed by Linus Torvalds
parent c157d37674
commit d0db466326
1 changed files with 10 additions and 1 deletions

View File

@ -71,6 +71,11 @@ static void show_diff_empty(struct cache_entry *ce)
unsigned char type[20], *p, *end; unsigned char type[20], *p, *end;


old = read_sha1_file(ce->sha1, type, &size); old = read_sha1_file(ce->sha1, type, &size);
if (! old) {
error("unable to read blob object for %s (%s)", ce->name,
sha1_to_hex(ce->sha1));
return;
}
if (size > 0) { if (size > 0) {
int startline = 1; int startline = 1;
int c = 0; int c = 0;
@ -195,6 +200,10 @@ int main(int argc, char **argv)
continue; continue;


old = read_sha1_file(ce->sha1, type, &size); old = read_sha1_file(ce->sha1, type, &size);
if (! old)
error("unable to read blob object for %s (%s)",
ce->name, sha1_to_hex(ce->sha1));
else
show_differences(ce->name, old, size); show_differences(ce->name, old, size);
free(old); free(old);
} }