{"thread":{"id":"7272","subject":"[PATCH] local-fetch.c: some error printing cleanup","startedAt":"2007-03-16T17:20:19Z","lastAt":"2007-03-16T17:20:19Z","messageCount":1,"participants":["Nicolas Pitre"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"37262","messageId":"alpine.LFD.0.83.0703161318210.18328@xanadu.home","threadId":"7272","inReplyTo":null,"subject":"[PATCH] local-fetch.c: some error printing cleanup","fromName":"Nicolas Pitre","fromEmail":"nico@cam.org","sentAt":"2007-03-16T17:20:19Z","receivedAt":"2007-03-16T17:20:19Z","isPatch":true,"sender":{"key":"nico@fluxnic.net","avatar":"https://avatars.githubusercontent.com/u/702790?v=4"},"body":"Signed-off-by: Nicolas Pitre <nico@cam.org>\n\ndiff --git a/local-fetch.c b/local-fetch.c\nindex 7cfe8b3..4b650ef 100644\n--- a/local-fetch.c\n+++ b/local-fetch.c\n@@ -64,9 +64,9 @@ static int copy_file(const char *source, char *dest, const char *hex,\n \t\t}\n \t\t/* If we got ENOENT there is no point continuing. */\n \t\tif (errno == ENOENT) {\n-\t\t\tif (warn_if_not_exists)\n-\t\t\t\tfprintf(stderr, \"does not exist %s\\n\", source);\n-\t\t\treturn -1;\n+\t\t\tif (!warn_if_not_exists)\n+\t\t\t\treturn -1;\n+\t\t\treturn error(\"does not exist %s\", source);\n \t\t}\n \t}\n \tif (use_symlink) {\n@@ -74,9 +74,8 @@ static int copy_file(const char *source, char *dest, const char *hex,\n \t\tif (stat(source, &st)) {\n \t\t\tif (!warn_if_not_exists && errno == ENOENT)\n \t\t\t\treturn -1;\n-\t\t\tfprintf(stderr, \"cannot stat %s: %s\\n\", source,\n-\t\t\t\tstrerror(errno));\n-\t\t\treturn -1;\n+\t\t\treturn error(\"cannot stat %s: %s\", source,\n+\t\t\t\t     strerror(errno));\n \t\t}\n \t\tif (!symlink(source, dest)) {\n \t\t\tpull_say(\"symlink %s\\n\", hex);\n@@ -90,25 +89,21 @@ static int copy_file(const char *source, char *dest, const char *hex,\n \t\tif (ifd < 0) {\n \t\t\tif (!warn_if_not_exists && errno == ENOENT)\n \t\t\t\treturn -1;\n-\t\t\tfprintf(stderr, \"cannot open %s\\n\", source);\n-\t\t\treturn -1;\n+\t\t\treturn error(\"cannot open %s\", source);\n \t\t}\n \t\tofd = open(dest, O_WRONLY | O_CREAT | O_EXCL, 0666);\n \t\tif (ofd < 0) {\n-\t\t\tfprintf(stderr, \"cannot open %s\\n\", dest);\n \t\t\tclose(ifd);\n-\t\t\treturn -1;\n+\t\t\treturn error(\"cannot open %s\", dest);\n \t\t}\n \t\tstatus = copy_fd(ifd, ofd);\n \t\tclose(ofd);\n \t\tif (status)\n-\t\t\tfprintf(stderr, \"cannot write %s\\n\", dest);\n-\t\telse\n-\t\t\tpull_say(\"copy %s\\n\", hex);\n-\t\treturn status;\n+\t\t\treturn error(\"cannot write %s\", dest);\n+\t\tpull_say(\"copy %s\\n\", hex);\n+\t\treturn 0;\n \t}\n-\tfprintf(stderr, \"failed to copy %s with given copy methods.\\n\", hex);\n-\treturn -1;\n+\treturn error(\"failed to copy %s with given copy methods.\", hex);\n }\n \n static int fetch_pack(const unsigned char *sha1)\n@@ -181,13 +176,11 @@ int fetch_ref(char *ref, unsigned char *sha1)\n \tifd = open(filename, O_RDONLY);\n \tif (ifd < 0) {\n \t\tclose(ifd);\n-\t\tfprintf(stderr, \"cannot open %s\\n\", filename);\n-\t\treturn -1;\n+\t\treturn error(\"cannot open %s\", filename);\n \t}\n \tif (read_in_full(ifd, hex, 40) != 40 || get_sha1_hex(hex, sha1)) {\n \t\tclose(ifd);\n-\t\tfprintf(stderr, \"cannot read from %s\\n\", filename);\n-\t\treturn -1;\n+\t\treturn error(\"cannot read from %s\", filename);\n \t}\n \tclose(ifd);\n \tpull_say(\"ref %s\\n\", sha1_to_hex(sha1));\n"}]}