{"thread":{"id":"24068","subject":"[PATCH] sha1_file: Show the the type and path to corrupt objects","startedAt":"2010-06-10T12:47:01Z","lastAt":"2010-06-10T12:47:01Z","messageCount":1,"participants":["Ævar Arnfjörð Bjarmason"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"143424","messageId":"1276174021-9544-1-git-send-email-avarab@gmail.com","threadId":"24068","inReplyTo":null,"subject":"[PATCH] sha1_file: Show the the type and path to corrupt objects","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2010-06-10T12:47:01Z","receivedAt":"2010-06-10T12:47:01Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"Change the error message that's displayed when we encounter corrupt\nobjects to be more specific. We now print the type (loose or packed)\nof corrupted objects, along with the full path to the file in\nquestion.\n\nBefore:\n\n    $ git cat-file blob 909ef997367880aaf2133bafa1f1a71aa28e09df\n    fatal: object 909ef997367880aaf2133bafa1f1a71aa28e09df is corrupted\n\nAfter:\n\n    $ git cat-file blob 909ef997367880aaf2133bafa1f1a71aa28e09df\n    fatal: loose object 909ef997367880aaf2133bafa1f1a71aa28e09df (stored in .git/objects/90/9ef997367880aaf2133bafa1f1a71aa28e09df) is corrupted\n\nKnowing the path helps to quickly analyze what's wrong:\n\n    $ file .git/objects/90/9ef997367880aaf2133bafa1f1a71aa28e09df\n    .git/objects/90/9ef997367880aaf2133bafa1f1a71aa28e09df: empty\n\nSigned-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\n---\n sha1_file.c |   13 +++++++++++--\n 1 files changed, 11 insertions(+), 2 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex d8e61a6..98e61b1 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -2084,6 +2084,7 @@ void *read_sha1_file_repl(const unsigned char *sha1,\n {\n \tconst unsigned char *repl = lookup_replace_object(sha1);\n \tvoid *data = read_object(repl, type, size);\n+\tchar *path;\n \n \t/* die if we replaced an object with one that does not exist */\n \tif (!data && repl != sha1)\n@@ -2091,8 +2092,16 @@ void *read_sha1_file_repl(const unsigned char *sha1,\n \t\t    sha1_to_hex(repl), sha1_to_hex(sha1));\n \n \t/* legacy behavior is to die on corrupted objects */\n-\tif (!data && (has_loose_object(repl) || has_packed_and_bad(repl)))\n-\t\tdie(\"object %s is corrupted\", sha1_to_hex(repl));\n+\tif (!data) {\n+\t\tif (has_loose_object(repl)) {\n+\t\t\tpath = sha1_file_name(sha1);\n+\t\t\tdie(\"loose object %s (stored in %s) is corrupted\", sha1_to_hex(repl), path);\n+\t\t}\n+\t\tif (has_packed_and_bad(repl)) {\n+\t\t\tpath = sha1_pack_name(sha1);\n+\t\t\tdie(\"packed object %s (stored in %s) is corrupted\", sha1_to_hex(repl), path);\n+\t\t}\n+\t}\n \n \tif (replacement)\n \t\t*replacement = repl;\n-- \n1.7.1.251.g92a7.dirty\n"}]}