Commit 51760bc1 by Carlos Martín Nieto Committed by Vicent Marti

pkt: get rid of the chunked support

It was a bad idea.

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
parent e5e92c1f
...@@ -152,20 +152,6 @@ int gitno_close(GIT_SOCKET s) ...@@ -152,20 +152,6 @@ int gitno_close(GIT_SOCKET s)
} }
#endif #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) int gitno_select_in(gitno_buffer *buf, long int sec, long int usec)
{ {
fd_set fds; fd_set fds;
......
...@@ -268,16 +268,10 @@ int git_pkt_buffer_flush(git_buf *buf) ...@@ -268,16 +268,10 @@ int git_pkt_buffer_flush(git_buf *buf)
return git_buf_oom(buf) ? GIT_ENOMEM : GIT_SUCCESS; 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"; 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); 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 ...@@ -356,7 +350,7 @@ int git_pkt_buffer_wants(git_headarray *refs, git_transport_caps *caps, git_buf
return git_pkt_buffer_flush(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; unsigned int i = 0;
int error = GIT_SUCCESS; int error = GIT_SUCCESS;
...@@ -391,17 +385,12 @@ int git_pkt_send_wants(git_headarray *refs, git_transport_caps *caps, int fd, in ...@@ -391,17 +385,12 @@ int git_pkt_send_wants(git_headarray *refs, git_transport_caps *caps, int fd, in
continue; continue;
git_oid_fmt(buf + strlen(WANT_PREFIX), &head->oid); 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); error = gitno_send(fd, buf, strlen(buf), 0);
if (error < GIT_SUCCESS) if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to send want pkt"); 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 " #define HAVE_PREFIX "0032have "
...@@ -416,16 +405,10 @@ int git_pkt_buffer_have(git_oid *oid, git_buf *buf) ...@@ -416,16 +405,10 @@ int git_pkt_buffer_have(git_oid *oid, git_buf *buf)
return git_buf_oom(buf) ? GIT_ENOMEM : GIT_SUCCESS; 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"; 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); git_oid_fmt(buf + strlen(HAVE_PREFIX), oid);
return gitno_send(fd, buf, strlen(buf), 0); return gitno_send(fd, buf, strlen(buf), 0);
} }
...@@ -438,15 +421,9 @@ int git_pkt_buffer_done(git_buf *buf) ...@@ -438,15 +421,9 @@ int git_pkt_buffer_done(git_buf *buf)
return git_buf_oom(buf) ? GIT_ENOMEM : GIT_SUCCESS; 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"; 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); return gitno_send(fd, buf, strlen(buf), 0);
} }
...@@ -65,13 +65,13 @@ typedef struct { ...@@ -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_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_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_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_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_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); void git_pkt_free(git_pkt *pkt);
#endif #endif
...@@ -277,7 +277,7 @@ static int git_negotiate_fetch(git_transport *transport, git_repository *repo, g ...@@ -277,7 +277,7 @@ static int git_negotiate_fetch(git_transport *transport, git_repository *repo, g
char buff[128]; char buff[128];
gitno_buffer buf; 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) if (error < GIT_SUCCESS)
return git__rethrow(error, "Failed to send wants list"); 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 ...@@ -322,12 +322,12 @@ static int git_negotiate_fetch(git_transport *transport, git_repository *repo, g
*/ */
i = 0; i = 0;
while ((error = git_revwalk_next(&oid, walk)) == GIT_SUCCESS) { 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++; i++;
if (i % 20 == 0) { if (i % 20 == 0) {
const char *ptr = buf.data, *line_end; const char *ptr = buf.data, *line_end;
git_pkt *pkt; git_pkt *pkt;
git_pkt_send_flush(t->socket, 0); git_pkt_send_flush(t->socket);
while (1) { while (1) {
/* Wait for max. 1 second */ /* Wait for max. 1 second */
error = gitno_select_in(&buf, 1, 0); error = gitno_select_in(&buf, 1, 0);
...@@ -373,8 +373,8 @@ static int git_negotiate_fetch(git_transport *transport, git_repository *repo, g ...@@ -373,8 +373,8 @@ static int git_negotiate_fetch(git_transport *transport, git_repository *repo, g
error = GIT_SUCCESS; error = GIT_SUCCESS;
done: done:
git_pkt_send_flush(t->socket, 0); git_pkt_send_flush(t->socket);
git_pkt_send_done(t->socket, 0); git_pkt_send_done(t->socket);
cleanup: cleanup:
git_revwalk_free(walk); git_revwalk_free(walk);
...@@ -385,14 +385,14 @@ static int git_send_flush(git_transport *transport) ...@@ -385,14 +385,14 @@ static int git_send_flush(git_transport *transport)
{ {
transport_git *t = (transport_git *) 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) static int git_send_done(git_transport *transport)
{ {
transport_git *t = (transport_git *) 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) static int store_pack(char **out, gitno_buffer *buf, git_repository *repo)
...@@ -492,7 +492,7 @@ static int git_close(git_transport *transport) ...@@ -492,7 +492,7 @@ static int git_close(git_transport *transport)
int error; int error;
/* Can't do anything if there's an error, so don't bother checking */ /* 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); error = gitno_close(t->socket);
if (error < 0) if (error < 0)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment