{"thread":{"id":"3735","subject":"Fix error handling for nonexistent names","startedAt":"2006-03-27T00:28:20Z","lastAt":"2006-03-27T00:28:20Z","messageCount":1,"participants":["Linus Torvalds"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"18020","messageId":"Pine.LNX.4.64.0603261620130.15714@g5.osdl.org","threadId":"3735","inReplyTo":null,"subject":"Fix error handling for nonexistent names","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2006-03-27T00:28:20Z","receivedAt":"2006-03-27T00:28:20Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n[ This is an expanded version of a patch I sent out earlier: the \n  \"rev-parse.c\" part of it is identical to the earlier version, the \n  revision.c thing is new ]\n\nWhen passing in a pathname pattern without the \"--\" separator on the \ncommand line, we verify that the pathnames in question exist. However, \nthere were two bugs in that verification: \n\n - git-rev-parse would only check the first pathname, and silently allow \n   any invalid subsequent pathname, whether it existed or not (which \n   defeats the purpose of the check, and is also inconsistent with what \n   git-rev-list actually does)\n\n - git-rev-list (and \"git log\" etc) would check each filename, but if the \n   check failed, it would print the error using the first one, ie:\n\n\t[torvalds@g5 git]$ git log Makefile bad-file\n\tfatal: 'Makefile': No such file or directory\n\n   instead of saying that it's 'bad-file' that doesn't exist.\n\nThis fixes both bugs.\n\nSigned-off-by: Linus Torvalds <torvalds@osdl.org>\n---\ndiff --git a/rev-parse.c b/rev-parse.c\nindex 19a5ef7..8ca1c69 100644\n--- a/rev-parse.c\n+++ b/rev-parse.c\n@@ -174,7 +174,9 @@ int main(int argc, char **argv)\n \t\tchar *dotdot;\n \t\n \t\tif (as_is) {\n-\t\t\tshow_file(arg);\n+\t\t\tif (show_file(arg) && as_is < 2)\n+\t\t\t\tif (lstat(arg, &st) < 0)\n+\t\t\t\t\tdie(\"'%s': %s\", arg, strerror(errno));\n \t\t\tcontinue;\n \t\t}\n \t\tif (!strcmp(arg,\"-n\")) {\n@@ -194,7 +196,7 @@ int main(int argc, char **argv)\n \n \t\tif (*arg == '-') {\n \t\t\tif (!strcmp(arg, \"--\")) {\n-\t\t\t\tas_is = 1;\n+\t\t\t\tas_is = 2;\n \t\t\t\t/* Pass on the \"--\" if we show anything but files.. */\n \t\t\t\tif (filter & (DO_FLAGS | DO_REVS))\n \t\t\t\t\tshow_file(arg);\ndiff --git a/revision.c b/revision.c\nindex 12cd052..d67718c 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -649,7 +649,7 @@ int setup_revisions(int argc, const char\n \t\t\t/* If we didn't have a \"--\", all filenames must exist */\n \t\t\tfor (j = i; j < argc; j++) {\n \t\t\t\tif (lstat(argv[j], &st) < 0)\n-\t\t\t\t\tdie(\"'%s': %s\", arg, strerror(errno));\n+\t\t\t\t\tdie(\"'%s': %s\", argv[j], strerror(errno));\n \t\t\t}\n \t\t\trevs->prune_data = get_pathspec(revs->prefix, argv + i);\n \t\t\tbreak;\n"}]}