{"thread":{"id":"447","subject":"[PATCH] Short-cut error return path in git-local-pull.","startedAt":"2005-05-03T00:26:17Z","lastAt":"2005-05-03T00:26:17Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"2421","messageId":"7vll6xnoie.fsf@assigned-by-dhcp.cox.net","threadId":"447","inReplyTo":null,"subject":"[PATCH] Short-cut error return path in git-local-pull.","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-05-03T00:26:17Z","receivedAt":"2005-05-03T00:26:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"When git-local-pull with -l option gets ENOENT attempting to create\na hard link, there is no point falling back to other copy methods.\nThis patch implements a short-cut to detect that case.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\nlocal-pull.c |   25 ++++++++++++++++---------\n1 files changed, 16 insertions(+), 9 deletions(-)\n\n--- a/local-pull.c\n+++ b/local-pull.c\n@@ -39,12 +39,19 @@ int fetch(unsigned char *sha1)\n \tfilename[object_name_start+1] = hex[1];\n \tfilename[object_name_start+2] = '/';\n \tstrcpy(filename + object_name_start + 3, hex + 2);\n-\tif (use_link && !link(filename, dest_filename)) {\n-\t\tsay(\"Hardlinked %s.\\n\", hex);\n-\t\treturn 0;\n+\tif (use_link) {\n+\t\tif (!link(filename, dest_filename)) {\n+\t\t\tsay(\"link %s\\n\", hex);\n+\t\t\treturn 0;\n+\t\t}\n+\t\t/* If we got ENOENT there is no point continuing. */\n+\t\tif (errno == ENOENT) {\n+\t\t\tfprintf(stderr, \"does not exist %s\\n\", filename);\n+\t\t\treturn -1;\n+\t\t}\n \t}\n \tif (use_symlink && !symlink(filename, dest_filename)) {\n-\t\tsay(\"Symlinked %s.\\n\", hex);\n+\t\tsay(\"symlink %s\\n\", hex);\n \t\treturn 0;\n \t}\n \tif (use_filecopy) {\n@@ -54,13 +61,13 @@ int fetch(unsigned char *sha1)\n \t\tifd = open(filename, O_RDONLY);\n \t\tif (ifd < 0 || fstat(ifd, &st) < 0) {\n \t\t\tclose(ifd);\n-\t\t\tfprintf(stderr, \"Cannot open %s\\n\", filename);\n+\t\t\tfprintf(stderr, \"cannot open %s\\n\", filename);\n \t\t\treturn -1;\n \t\t}\n \t\tmap = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, ifd, 0);\n \t\tclose(ifd);\n \t\tif (-1 == (int)(long)map) {\n-\t\t\tfprintf(stderr, \"Cannot mmap %s\\n\", filename);\n+\t\t\tfprintf(stderr, \"cannot mmap %s\\n\", filename);\n \t\t\treturn -1;\n \t\t}\n \t\tofd = open(dest_filename, O_WRONLY | O_CREAT | O_EXCL, 0666);\n@@ -69,13 +76,13 @@ int fetch(unsigned char *sha1)\n \t\tmunmap(map, st.st_size);\n \t\tclose(ofd);\n \t\tif (status)\n-\t\t\tfprintf(stderr, \"Cannot write %s (%ld bytes)\\n\",\n+\t\t\tfprintf(stderr, \"cannot write %s (%ld bytes)\\n\",\n \t\t\t\tdest_filename, st.st_size);\n \t\telse\n-\t\t\tsay(\"Copied %s.\\n\", hex);\n+\t\t\tsay(\"copy %s\\n\", hex);\n \t\treturn status;\n \t}\n-\tfprintf(stderr, \"No copy method was provided to copy %s.\\n\", hex);\n+\tfprintf(stderr, \"failed to copy %s with given copy methods.\\n\", hex);\n \treturn -1;\n }\n \n\n"}]}