git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH] sha1_file: Show the the type and path to corrupt objects
Date: Thu, 10 Jun 2010 12:47:01 +0000	[thread overview]
Message-ID: <1276174021-9544-1-git-send-email-avarab@gmail.com> (raw)

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>
---
 sha1_file.c |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/sha1_file.c b/sha1_file.c
index d8e61a6..98e61b1 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2084,6 +2084,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)
@@ -2091,8 +2092,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;
-- 
1.7.1.251.g92a7.dirty

                 reply	other threads:[~2010-06-10 12:47 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1276174021-9544-1-git-send-email-avarab@gmail.com \
    --to=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).