[PATCH] Simplify send_git_request()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxx>
---
 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

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]