{"thread":{"id":"24720","subject":"[PATCH] Simplify send_git_request()","startedAt":"2010-08-12T15:25:23Z","lastAt":"2010-08-12T15:25:23Z","messageCount":1,"participants":["Ilari Liusvaara"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"147909","messageId":"1281626723-20178-1-git-send-email-ilari.liusvaara@elisanet.fi","threadId":"24720","inReplyTo":null,"subject":"[PATCH] Simplify send_git_request()","fromName":"Ilari Liusvaara","fromEmail":"ilari.liusvaara@elisanet.fi","sentAt":"2010-08-12T15:25:23Z","receivedAt":"2010-08-12T15:25:23Z","isPatch":true,"sender":{"key":"ilari.liusvaara@elisanet.fi","avatar":null},"body":"Send_git_request() of remote-ext.c is more complicated than it needs to\nbe. Simplify it by using sprintf() and write_in_full().\n\nSigned-off-by: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>\n---\n builtin/remote-ext.c |   54 +++++++------------------------------------------\n 1 files changed, 8 insertions(+), 46 deletions(-)\n\ndiff --git a/builtin/remote-ext.c b/builtin/remote-ext.c\nindex e9852ca..d861f0a 100644\n--- a/builtin/remote-ext.c\n+++ b/builtin/remote-ext.c\n@@ -169,8 +169,6 @@ static void send_git_request(int stdin_fd, const char *serv, const char *repo,\n {\n \tsize_t bufferspace;\n \tsize_t wpos = 0;\n-\tsize_t spos = 0;\n-\tsize_t tmp;\n \tchar* buffer;\n \n \t/*\n@@ -186,53 +184,17 @@ static void send_git_request(int stdin_fd, const char *serv, const char *repo,\n \t\tdie(\"Request too large to send\");\n \tbuffer = xmalloc(bufferspace);\n \n-\t/* Packet length. */\n-\tsprintf(buffer + wpos, \"%04x\", (unsigned)bufferspace);\n-\twpos += 4;\n+\t/* Make the packet. */\n+\twpos = sprintf(buffer, \"%04x%s %s%c\", (unsigned)bufferspace,\n+\t\tserv, repo, 0);\n \n-\t/* Service. */\n-\ttmp = strlen(serv);\n-\tmemcpy(buffer + wpos, serv, tmp);\n-\twpos += tmp;\n-\n-\t/* Space. */\n-\tbuffer[wpos++] = ' ';\n-\n-\t/* Repo. */\n-\ttmp = strlen(repo);\n-\tmemcpy(buffer + wpos, repo, tmp);\n-\twpos += tmp;\n-\n-\t/* NUL. */\n-\tbuffer[wpos++] = '\\0';\n-\n-\t/* Vhost if any. */\n-\tif (vhost) {\n-\t\t/* Header name. */\n-\t\tstrcpy(buffer + wpos, \"host=\");\n-\t\twpos += 5;\n-\n-\t\t/* Actual vhost */\n-\t\ttmp = strlen(vhost);\n-\t\tmemcpy(buffer + wpos, vhost, tmp);\n-\t\twpos += tmp;\n-\n-\t\t/* NUL. */\n-\t\tbuffer[wpos++] = '\\0';\n-\t}\n+\t/* Add vhost if any. */\n+\tif (vhost)\n+\t\tsprintf(buffer + wpos, \"host=%s%c\", vhost, 0);\n \n \t/* Send the request */\n-\twhile (spos < wpos) {\n-\t\tssize_t r;\n-\t\tr = write(stdin_fd, buffer + spos, wpos - spos);\n-\t\tif (r < 0 && errno != EINTR && errno != EAGAIN &&\n-\t\t\terrno != EWOULDBLOCK)\n-\t\t\tdie_errno(\"Failed to send request\");\n-\t\telse if (r < 0)\n-\t\t\tcontinue;\t/* Try again. */\n-\t\telse\n-\t\t\tspos += r;\n-\t}\n+\tif (write_in_full(stdin_fd, buffer, bufferspace) < 0)\n+\t\tdie_errno(\"Failed to send request\");\n \n \tfree(buffer);\n }\n-- \n1.7.2.1.9.g1ccab.dirty\n"}]}