diff options
| author | Carlos Martín Nieto <carlos@cmartin.tk> | 2011-10-26 18:06:36 -0700 |
|---|---|---|
| committer | Carlos Martín Nieto <carlos@cmartin.tk> | 2011-11-18 21:03:23 +0100 |
| commit | 40a40e8e9daa8187450258ba538c90d70eac12fe (patch) | |
| tree | 800726fb387985bf8bb30f73aae62e0b6a0c49d8 /src/transports/git.c | |
| parent | e4c93a392763a006d11e1c1dd01c12f85498dad5 (diff) | |
| download | libgit2-40a40e8e9daa8187450258ba538c90d70eac12fe.tar.gz | |
net: move the reference storage to common code
Diffstat (limited to 'src/transports/git.c')
| -rw-r--r-- | src/transports/git.c | 45 |
1 files changed, 16 insertions, 29 deletions
diff --git a/src/transports/git.c b/src/transports/git.c index c2014529b..2ee2e4831 100644 --- a/src/transports/git.c +++ b/src/transports/git.c @@ -20,9 +20,11 @@ #include "filebuf.h" #include "repository.h" #include "fetch.h" +#include "protocol.h" typedef struct { git_transport parent; + git_protocol proto; GIT_SOCKET socket; git_vector refs; git_remote_head **heads; @@ -126,11 +128,7 @@ static int do_connect(transport_git *t, const char *url) static int store_refs(transport_git *t) { gitno_buffer *buf = &t->buf; - git_vector *refs = &t->refs; int error = GIT_SUCCESS; - const char *line_end, *ptr; - git_pkt *pkt; - while (1) { error = gitno_recv(buf); @@ -139,34 +137,20 @@ static int store_refs(transport_git *t) if (error == GIT_SUCCESS) /* Orderly shutdown, so exit */ return GIT_SUCCESS; - ptr = buf->data; - while (1) { - if (buf->offset == 0) - break; - error = git_pkt_parse_line(&pkt, ptr, &line_end, buf->offset); - /* - * If the error is GIT_ESHORTBUFFER, it means the buffer - * isn't long enough to satisfy the request. Break out and - * wait for more input. - * On any other error, fail. - */ - if (error == GIT_ESHORTBUFFER) { - break; - } - if (error < GIT_SUCCESS) { - return error; - } - - /* Get rid of the part we've used already */ - gitno_consume(buf, line_end); + error = git_protocol_store_refs(&t->proto, buf->data, buf->offset); + if (error == GIT_ESHORTBUFFER) { + gitno_consume_n(buf, buf->len); + continue; + } - error = git_vector_insert(refs, pkt); - if (error < GIT_SUCCESS) - return error; + if (error < GIT_SUCCESS) + return git__rethrow(error, "Failed to store refs"); - if (pkt->type == GIT_PKT_FLUSH) - return GIT_SUCCESS; + gitno_consume_n(buf, buf->offset); + if (t->proto.flush) { /* No more refs */ + t->proto.flush = 0; + return GIT_SUCCESS; } } @@ -476,6 +460,7 @@ static void git_free(git_transport *transport) git_vector_free(refs); git__free(t->heads); + git_buf_free(&t->proto.buf); git__free(t->parent.url); git__free(t); } @@ -501,6 +486,8 @@ int git_transport_git(git_transport **out) t->parent.download_pack = git_download_pack; t->parent.close = git_close; t->parent.free = git_free; + t->proto.refs = &t->refs; + t->proto.transport = (git_transport *) t; *out = (git_transport *) t; |
