@matheusbsbs / matheus-bagliano / commits / e8b15e6156
Fork 0

sha1_file: Show the the type and path to corrupt objects

Change the error message that's displayed when we encounter corrupt objects to be more specific. We now print the type (loose or packed) of corrupted objects, along with the full path to the file in question. Before: $ git cat-file blob 909ef997367880aaf2133bafa1f1a71aa28e09df fatal: object 909ef997367880aaf2133bafa1f1a71aa28e09df is corrupted After: $ git cat-file blob 909ef997367880aaf2133bafa1f1a71aa28e09df fatal: loose object 909ef997367880aaf2133bafa1f1a71aa28e09df (stored in .git/objects/90/9ef997367880aaf2133bafa1f1a71aa28e09df) is corrupted Knowing the path helps to quickly analyze what's wrong: $ file .git/objects/90/9ef997367880aaf2133bafa1f1a71aa28e09df .git/objects/90/9ef997367880aaf2133bafa1f1a71aa28e09df: empty Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Jun 10, 2010 at 12:47 UTC e8b15e6156fc361d3cb0e093747dab840d58fc7e
1 file changed +11 -2
sha1_file.c
+11 -2
@@ -2086,6 +2086,7 @@ void *read_sha1_file_repl(const unsigned char *sha1,
2086 {
2087 const unsigned char *repl = lookup_replace_object(sha1);
2088 void *data = read_object(repl, type, size);
2089 + char *path;
2090
2091 /* die if we replaced an object with one that does not exist */
2092 if (!data && repl != sha1)
@@ -2093,8 +2094,16 @@ void *read_sha1_file_repl(const unsigned char *sha1,
2094 sha1_to_hex(repl), sha1_to_hex(sha1));
2095
2096 /* legacy behavior is to die on corrupted objects */
2096 - if (!data && (has_loose_object(repl) || has_packed_and_bad(repl)))
2097 - die("object %s is corrupted", sha1_to_hex(repl));
2097 + if (!data) {
2098 + if (has_loose_object(repl)) {
2099 + path = sha1_file_name(sha1);
2100 + die("loose object %s (stored in %s) is corrupted", sha1_to_hex(repl), path);
2101 + }
2102 + if (has_packed_and_bad(repl)) {
2103 + path = sha1_pack_name(sha1);
2104 + die("packed object %s (stored in %s) is corrupted", sha1_to_hex(repl), path);
2105 + }
2106 + }
2107
2108 if (replacement)
2109 *replacement = repl;