{"thread":{"id":"26714","subject":"[Buglet] \"git show <random-40-hexdigit>\" gives an unclear error message","startedAt":"2011-03-11T18:28:08Z","lastAt":"2011-03-14T17:40:55Z","messageCount":3,"participants":["Junio C Hamano","Jakob Pfender"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"163240","messageId":"7vzkp1y0jr.fsf@alter.siamese.dyndns.org","threadId":"26714","inReplyTo":null,"subject":"[Buglet] \"git show <random-40-hexdigit>\" gives an unclear error message","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-03-11T18:28:08Z","receivedAt":"2011-03-11T18:28:08Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Here is one who wants to tackle potentially a low-hanging fruit.\n\n  $ git cat-file -p 4cd96ce446ab653325a0e47fad73e94c99c57dd2\n  error: unable to find 4cd96ce446ab653325a0e47fad73e94c99c57dd2\n  fatal: Not a valid object name 4cd96ce446ab653325a0e47fad73e94c99c57dd2\n\nThis looks sensible and understandable, even though you could argue that\nwe don't have to say the same thing twice.  In the same repository:\n\n  $ git show 4cd96ce446ab653325a0e47fad73e94c99c57dd3\n  fatal: bad object 4cd96ce446ab653325a0e47fad73e94c99c57dd3\n\nThis is bad, as it sounds as if we found the named object but it is\ncorrupt.\n"},{"id":"163311","messageId":"4D7E303A.5090605@elegosoft.com","threadId":"26714","inReplyTo":"7vzkp1y0jr.fsf@alter.siamese.dyndns.org","subject":"[PATCH] revision.c: Clarify error message for missing objects","fromName":"Jakob Pfender","fromEmail":"jpfender@elegosoft.com","sentAt":"2011-03-14T15:11:54Z","receivedAt":"2011-03-14T15:11:54Z","isPatch":true,"sender":{"key":"jpfender@elegosoft.com","avatar":null},"body":"[Sorry Junio, accidentally sent this to just you the first time around]\n\nIf \"git show\" is invoked on a hash for a file that doesn't exist, the\nproduced error message was \"fatal: bad object <hash>\". This is\nmisleading as the object isn't bad, but missing. As a matter of fact, if\nan object is bad, this error message is never produced, because\nparse_object() terminates with its own error message if the object is\ncorrupt.\n\nThis patch introduces a check to see whether an object exists (with the\nappropriate error message if it doesn't) and removes the unnecessary and\nmisleading original error message if parse_object() fails.\n\nSigned-off-by: Jakob Pfender <jpfender@elegosoft.com>\n---\n  revision.c |    4 ++--\n  1 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/revision.c b/revision.c\nindex 86d2470..085aac2 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -173,9 +173,9 @@ static struct object *get_reference(struct rev_info \n*revs, const char *name, con\n  {\n      struct object *object;\n\n+    if (sha1_object_info(sha1, NULL) < 0)\n+        die(\"Not a valid object name %s\", name);\n      object = parse_object(sha1);\n-    if (!object)\n-        die(\"bad object %s\", name);\n      object->flags |= flags;\n      return object;\n  }\n-- \n1.7.0.4\n"},{"id":"163321","messageId":"7vsjupeh20.fsf@alter.siamese.dyndns.org","threadId":"26714","inReplyTo":"4D7E303A.5090605@elegosoft.com","subject":"Re: [PATCH] revision.c: Clarify error message for missing objects","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-03-14T17:40:55Z","receivedAt":"2011-03-14T17:40:55Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jakob Pfender <jpfender@elegosoft.com> writes:\n\n> This patch introduces a check to see whether an object exists (with the\n> appropriate error message if it doesn't) and removes the unnecessary and\n> misleading original error message if parse_object() fails.\n\nHow does this interact with object replacement?\n\nI suspect the real issue is in read_sha1_file_repl() that says:\n\n    /*\n     * This function dies on corrupt objects; the callers who want to\n     * deal with them should arrange to call read_object() and give error\n     * messages themselves.\n     */\n\nwithout giving sufficient support for the callers that wish to use\nread_object() themselves to implement the object replacement logic.\n\n\n> Signed-off-by: Jakob Pfender <jpfender@elegosoft.com>\n> ---\n>  revision.c |    4 ++--\n>  1 files changed, 2 insertions(+), 2 deletions(-)\n>\n> diff --git a/revision.c b/revision.c\n> index 86d2470..085aac2 100644\n> --- a/revision.c\n> +++ b/revision.c\n> @@ -173,9 +173,9 @@ static struct object *get_reference(struct\n> rev_info *revs, const char *name, con\n>  {\n>      struct object *object;\n>\n> +    if (sha1_object_info(sha1, NULL) < 0)\n> +        die(\"Not a valid object name %s\", name);\n>      object = parse_object(sha1);\n> -    if (!object)\n> -        die(\"bad object %s\", name);\n>      object->flags |= flags;\n>      return object;\n>  }\n"}]}