git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Simplify send_git_request()

From
ILIlari Liusvaara <ilari.liusvaara@elisanet.fi>
Date
Aug 12, 2010, 15:25 UTC
Message-ID
<1281626723-20178-1-git-send-email-ilari.liusvaara@elisanet.fi>

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
Message 1 of 1 in “Simplify send_git_request()”
  1. Simplify send_git_request()Ilari Liusvaara, Aug 12, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.