Commit 51760bc13d2699b34b0015b406242107cfa68b33

Carlos Martín Nieto 2011-10-05T18:11:22

pkt: get rid of the chunked support It was a bad idea. Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>

diff --git a/src/netops.c b/src/netops.c
index 5d17e17..dad296a 100644
--- a/src/netops.c
+++ b/src/netops.c
@@ -152,20 +152,6 @@ int gitno_close(GIT_SOCKET s)
 }
 #endif
 
-int gitno_send_chunk_size(int s, size_t len)
-{
-	char str[8] = {0};
-	int ret;
-
-	ret = p_snprintf(str, sizeof(str), "%zx\r\n", len);
-	if (ret >= (int) sizeof(str)) {
-		return git__throw(GIT_ESHORTBUFFER, "Your number is too big");
-	}
-
-	return gitno_send(s, str, ret, 0 /* TODO: MSG_MORE */);
-}
-
-
 int gitno_select_in(gitno_buffer *buf, long int sec, long int usec)
 {
 	fd_set fds;
diff --git a/src/pkt.c b/src/pkt.c
index 7aa225c..be850bc 100644
--- a/src/pkt.c
+++ b/src/pkt.c
@@ -268,16 +268,10 @@ int git_pkt_buffer_flush(git_buf *buf)
 	return git_buf_oom(buf) ? GIT_ENOMEM : GIT_SUCCESS;
 }
 
-int git_pkt_send_flush(int s, int chunked)
+int git_pkt_send_flush(int s)
 {
 	char flush[] = "0000";
-	int error;
 
-	if (chunked) {
-		error = gitno_send_chunk_size(s, strlen(flush));
-		if (error < GIT_SUCCESS)
-			return git__rethrow(error, "Failed to send chunk size");
-	}
 	return gitno_send(s, flush, strlen(flush), 0);
 }
 
@@ -356,7 +350,7 @@ int git_pkt_buffer_wants(git_headarray *refs, git_transport_caps *caps, git_buf 
 	return git_pkt_buffer_flush(buf);
 }
 
-int git_pkt_send_wants(git_headarray *refs, git_transport_caps *caps, int fd, int chunked)
+int git_pkt_send_wants(git_headarray *refs, git_transport_caps *caps, int fd)
 {
 	unsigned int i = 0;
 	int error = GIT_SUCCESS;
@@ -391,17 +385,12 @@ int git_pkt_send_wants(git_headarray *refs, git_transport_caps *caps, int fd, in
 			continue;
 
 		git_oid_fmt(buf + strlen(WANT_PREFIX), &head->oid);
-		if (chunked) {
-			error = gitno_send_chunk_size(fd, strlen(buf));
-			if (error < GIT_SUCCESS)
-				return git__rethrow(error, "Failed to send want chunk size");
-		}
 		error = gitno_send(fd, buf, strlen(buf), 0);
 		if (error < GIT_SUCCESS)
 			return git__rethrow(error, "Failed to send want pkt");
 	}
 
-	return git_pkt_send_flush(fd, chunked);
+	return git_pkt_send_flush(fd);
 }
 
 #define HAVE_PREFIX "0032have "
@@ -416,16 +405,10 @@ int git_pkt_buffer_have(git_oid *oid, git_buf *buf)
 	return git_buf_oom(buf) ? GIT_ENOMEM : GIT_SUCCESS;
 }
 
-int git_pkt_send_have(git_oid *oid, int fd, int chunked)
+int git_pkt_send_have(git_oid *oid, int fd)
 {
 	char buf[] = "0032have 0000000000000000000000000000000000000000\n";
-	int error;
 
-	if (chunked) {
-		error = gitno_send_chunk_size(fd, strlen(buf));
-		if (error < GIT_SUCCESS)
-			return git__rethrow(error, "Failed to send chunk size");
-	}
 	git_oid_fmt(buf + strlen(HAVE_PREFIX), oid);
 	return gitno_send(fd, buf, strlen(buf), 0);
 }
@@ -438,15 +421,9 @@ int git_pkt_buffer_done(git_buf *buf)
 	return git_buf_oom(buf) ? GIT_ENOMEM : GIT_SUCCESS;
 }
 
-int git_pkt_send_done(int fd, int chunked)
+int git_pkt_send_done(int fd)
 {
 	char buf[] = "0009done\n";
-	int error;
 
-	if (chunked) {
-		error = gitno_send_chunk_size(fd, strlen(buf));
-		if (error < GIT_SUCCESS)
-			return git__rethrow(error, "Failed to send chunk size");
-	}
 	return gitno_send(fd, buf, strlen(buf), 0);
 }
diff --git a/src/pkt.h b/src/pkt.h
index 44c36b4..88711f2 100644
--- a/src/pkt.h
+++ b/src/pkt.h
@@ -65,13 +65,13 @@ typedef struct {
 
 int git_pkt_parse_line(git_pkt **head, const char *line, const char **out, size_t len);
 int git_pkt_buffer_flush(git_buf *buf);
-int git_pkt_send_flush(int s, int chunked);
+int git_pkt_send_flush(int s);
 int git_pkt_buffer_done(git_buf *buf);
-int git_pkt_send_done(int s, int chunked);
+int git_pkt_send_done(int s);
 int git_pkt_buffer_wants(git_headarray *refs, git_transport_caps *caps, git_buf *buf);
-int git_pkt_send_wants(git_headarray *refs, git_transport_caps *caps, int fd, int chunked);
+int git_pkt_send_wants(git_headarray *refs, git_transport_caps *caps, int fd);
 int git_pkt_buffer_have(git_oid *oid, git_buf *buf);
-int git_pkt_send_have(git_oid *oid, int fd, int chunked);
+int git_pkt_send_have(git_oid *oid, int fd);
 void git_pkt_free(git_pkt *pkt);
 
 #endif
diff --git a/src/transport_git.c b/src/transport_git.c
index e4c5a07..e32b333 100644
--- a/src/transport_git.c
+++ b/src/transport_git.c
@@ -277,7 +277,7 @@ static int git_negotiate_fetch(git_transport *transport, git_repository *repo, g
 	char buff[128];
 	gitno_buffer buf;
 
-	error = git_pkt_send_wants(wants, &t->caps, t->socket, 0);
+	error = git_pkt_send_wants(wants, &t->caps, t->socket);
 	if (error < GIT_SUCCESS)
 		return git__rethrow(error, "Failed to send wants list");
 
@@ -322,12 +322,12 @@ static int git_negotiate_fetch(git_transport *transport, git_repository *repo, g
 	 */
 	i = 0;
 	while ((error = git_revwalk_next(&oid, walk)) == GIT_SUCCESS) {
-		error = git_pkt_send_have(&oid, t->socket, 1);
+		error = git_pkt_send_have(&oid, t->socket);
 		i++;
 		if (i % 20 == 0) {
 			const char *ptr = buf.data, *line_end;
 			git_pkt *pkt;
-			git_pkt_send_flush(t->socket, 0);
+			git_pkt_send_flush(t->socket);
 			while (1) {
 				/* Wait for max. 1 second */
 				error = gitno_select_in(&buf, 1, 0);
@@ -373,8 +373,8 @@ static int git_negotiate_fetch(git_transport *transport, git_repository *repo, g
 		error = GIT_SUCCESS;
 
 done:
-	git_pkt_send_flush(t->socket, 0);
-	git_pkt_send_done(t->socket, 0);
+	git_pkt_send_flush(t->socket);
+	git_pkt_send_done(t->socket);
 
 cleanup:
 	git_revwalk_free(walk);
@@ -385,14 +385,14 @@ static int git_send_flush(git_transport *transport)
 {
 	transport_git *t = (transport_git *) transport;
 
-	return git_pkt_send_flush(t->socket, 1);
+	return git_pkt_send_flush(t->socket);
 }
 
 static int git_send_done(git_transport *transport)
 {
 	transport_git *t = (transport_git *) transport;
 
-	return git_pkt_send_done(t->socket, 1);
+	return git_pkt_send_done(t->socket);
 }
 
 static int store_pack(char **out, gitno_buffer *buf, git_repository *repo)
@@ -492,7 +492,7 @@ static int git_close(git_transport *transport)
 	int error;
 
 	/* Can't do anything if there's an error, so don't bother checking  */
-	git_pkt_send_flush(t->socket, 0);
+	git_pkt_send_flush(t->socket);
 	error = gitno_close(t->socket);
 
 	if (error < 0)