* [PATCH] Simplify send_git_request()
@ 2010-08-12 15:25 Ilari Liusvaara
0 siblings, 0 replies; only message in thread
From: Ilari Liusvaara @ 2010-08-12 15:25 UTC (permalink / raw)
To: git
Send_git_request() of remote-ext.c is more complicated than it needs to
be. Simplify it by using sprintf() and write_in_full().
Signed-off-by: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
---
builtin/remote-ext.c | 54 +++++++------------------------------------------
1 files changed, 8 insertions(+), 46 deletions(-)
diff --git a/builtin/remote-ext.c b/builtin/remote-ext.c
index e9852ca..d861f0a 100644
--- a/builtin/remote-ext.c
+++ b/builtin/remote-ext.c
@@ -169,8 +169,6 @@ static void send_git_request(int stdin_fd, const char *serv, const char *repo,
{
size_t bufferspace;
size_t wpos = 0;
- size_t spos = 0;
- size_t tmp;
char* buffer;
/*
@@ -186,53 +184,17 @@ static void send_git_request(int stdin_fd, const char *serv, const char *repo,
die("Request too large to send");
buffer = xmalloc(bufferspace);
- /* Packet length. */
- sprintf(buffer + wpos, "%04x", (unsigned)bufferspace);
- wpos += 4;
+ /* Make the packet. */
+ wpos = sprintf(buffer, "%04x%s %s%c", (unsigned)bufferspace,
+ serv, repo, 0);
- /* Service. */
- tmp = strlen(serv);
- memcpy(buffer + wpos, serv, tmp);
- wpos += tmp;
-
- /* Space. */
- buffer[wpos++] = ' ';
-
- /* Repo. */
- tmp = strlen(repo);
- memcpy(buffer + wpos, repo, tmp);
- wpos += tmp;
-
- /* NUL. */
- buffer[wpos++] = '\0';
-
- /* Vhost if any. */
- if (vhost) {
- /* Header name. */
- strcpy(buffer + wpos, "host=");
- wpos += 5;
-
- /* Actual vhost */
- tmp = strlen(vhost);
- memcpy(buffer + wpos, vhost, tmp);
- wpos += tmp;
-
- /* NUL. */
- buffer[wpos++] = '\0';
- }
+ /* Add vhost if any. */
+ if (vhost)
+ sprintf(buffer + wpos, "host=%s%c", vhost, 0);
/* Send the request */
- while (spos < wpos) {
- ssize_t r;
- r = write(stdin_fd, buffer + spos, wpos - spos);
- if (r < 0 && errno != EINTR && errno != EAGAIN &&
- errno != EWOULDBLOCK)
- die_errno("Failed to send request");
- else if (r < 0)
- continue; /* Try again. */
- else
- spos += r;
- }
+ if (write_in_full(stdin_fd, buffer, bufferspace) < 0)
+ die_errno("Failed to send request");
free(buffer);
}
--
1.7.2.1.9.g1ccab.dirty
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2010-08-12 15:22 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-12 15:25 [PATCH] Simplify send_git_request() Ilari Liusvaara
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.