{"thread":{"id":"36637","subject":"[PATCH] index-pack: distinguish missing objects from type errors","startedAt":"2014-05-12T04:38:39Z","lastAt":"2014-05-12T04:38:39Z","messageCount":1,"participants":["Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"241275","messageId":"20140512043839.GA2252@sigill.intra.peff.net","threadId":"36637","inReplyTo":null,"subject":"[PATCH] index-pack: distinguish missing objects from type errors","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2014-05-12T04:38:39Z","receivedAt":"2014-05-12T04:38:39Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"When we fetch a pack that does not contain an object we\nexpected to receive, we get an error like:\n\n  $ git init --bare tmp.git && cd tmp.git\n  $ git fetch ../parent.git\n  [...]\n  error: Could not read 964953ec7bcc0245cb1d0db4095455edd21a2f2e\n  fatal: Failed to traverse parents of commit b8247b40caf6704fe52736cdece6d6aae87471aa\n  error: ../parent.git did not send all necessary objects\n\nThis comes from the check_everything_connected rev-list. If\nwe try cloning the same repo (rather than a fetch), we end\nup using index-pack's --check-self-contained-and-connected\noption instead, which produces output like:\n\n  $ git clone --no-local --bare parent.git tmp.git\n  [...]\n  fatal: object of unexpected type\n  fatal: index-pack failed\n\nNot only is the sha1 missing, but it's a misleading message.\nThere's no type problem, but rather a missing object\nproblem; we don't notice the difference because we simply\ncompare OBJ_BAD != OBJ_BLOB.  Let's provide a different\nmessage for this case:\n\n  $ git clone --no-local --bare parent.git tmp.git\n  fatal: did not receive expected object 6b00a8c61ed379d5f925a72c1987c9c52129d364\n  fatal: index-pack failed\n\nWhile we're at it, let's also improve a true type mismatch\nerror to look like\n\n  fatal: object 6b00a8c61ed379d5f925a72c1987c9c52129d364: expected type blob, got tree\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n builtin/index-pack.c | 9 +++++++--\n 1 file changed, 7 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex b9f6e12..35643e5 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -200,8 +200,13 @@ static unsigned check_object(struct object *obj)\n \tif (!(obj->flags & FLAG_CHECKED)) {\n \t\tunsigned long size;\n \t\tint type = sha1_object_info(obj->sha1, &size);\n-\t\tif (type != obj->type || type <= 0)\n-\t\t\tdie(_(\"object of unexpected type\"));\n+\t\tif (type <= 0)\n+\t\t\tdie(_(\"did not receive expected object %s\"),\n+\t\t\t      sha1_to_hex(obj->sha1));\n+\t\tif (type != obj->type)\n+\t\t\tdie(_(\"object %s: expected type %s, found %s\"),\n+\t\t\t    sha1_to_hex(obj->sha1),\n+\t\t\t    typename(obj->type), typename(type));\n \t\tobj->flags |= FLAG_CHECKED;\n \t\treturn 1;\n \t}\n-- \n2.0.0.rc1.436.g03cb729\n"}]}