X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=sha1_file.c;h=0cd9435619f1e0637584289b45d52c1cdd8a9460;hb=be254a0ea99b441a6c514cb8b25cd72357383700;hp=72de38909ef6b05f0aa709b78fd803c632a02044;hpb=b2ebbd8f1311608622ede7a1286839ef64edfc86;p=git.git diff --git a/sha1_file.c b/sha1_file.c index 72de38909..0cd943561 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -2086,6 +2086,7 @@ void *read_sha1_file_repl(const unsigned char *sha1, { const unsigned char *repl = lookup_replace_object(sha1); void *data = read_object(repl, type, size); + char *path; /* die if we replaced an object with one that does not exist */ if (!data && repl != sha1) @@ -2093,8 +2094,16 @@ void *read_sha1_file_repl(const unsigned char *sha1, sha1_to_hex(repl), sha1_to_hex(sha1)); /* legacy behavior is to die on corrupted objects */ - if (!data && (has_loose_object(repl) || has_packed_and_bad(repl))) - die("object %s is corrupted", sha1_to_hex(repl)); + if (!data) { + if (has_loose_object(repl)) { + path = sha1_file_name(sha1); + die("loose object %s (stored in %s) is corrupted", sha1_to_hex(repl), path); + } + if (has_packed_and_bad(repl)) { + path = sha1_pack_name(sha1); + die("packed object %s (stored in %s) is corrupted", sha1_to_hex(repl), path); + } + } if (replacement) *replacement = repl; @@ -2525,3 +2534,13 @@ int read_pack_header(int fd, struct pack_header *header) return PH_ERROR_PROTOCOL; return 0; } + +void assert_sha1_type(const unsigned char *sha1, enum object_type expect) +{ + enum object_type type = sha1_object_info(sha1, NULL); + if (type < 0) + die("%s is not a valid object", sha1_to_hex(sha1)); + if (type != expect) + die("%s is not a valid '%s' object", sha1_to_hex(sha1), + typename(expect)); +}