summaryrefslogtreecommitdiff
path: root/src/protocol.c
diff options
context:
space:
mode:
authorVicent Martí <tanoku@gmail.com>2012-05-02 15:59:02 -0700
committerVicent Martí <tanoku@gmail.com>2012-05-02 15:59:02 -0700
commit40879facad0337d954d4904e212af3b36cdb9465 (patch)
treeaea730551948c67bb1fb88098cf8a67d3ed3211d /src/protocol.c
parent2218fd57a50ceb851cb131939bf0747e072e40f6 (diff)
parent3fd99be98a91416dae77d65fe593965a0723fa8c (diff)
downloadlibgit2-40879facad0337d954d4904e212af3b36cdb9465.tar.gz
Merge branch 'new-error-handling' into development
Conflicts: .travis.yml include/git2/diff.h src/config_file.c src/diff.c src/diff_output.c src/mwindow.c src/path.c tests-clar/clar_helpers.c tests-clar/object/tree/frompath.c tests/t00-core.c tests/t03-objwrite.c tests/t08-tag.c tests/t10-refs.c tests/t12-repo.c tests/t18-status.c tests/test_helpers.c tests/test_main.c
Diffstat (limited to 'src/protocol.c')
-rw-r--r--src/protocol.c30
1 files changed, 19 insertions, 11 deletions
diff --git a/src/protocol.c b/src/protocol.c
index dd93623b3..a75354121 100644
--- a/src/protocol.c
+++ b/src/protocol.c
@@ -17,10 +17,12 @@ int git_protocol_store_refs(git_protocol *p, const char *data, size_t len)
const char *line_end, *ptr;
if (len == 0) { /* EOF */
- if (buf->size != 0)
- return p->error = git__throw(GIT_ERROR, "EOF and unprocessed data");
- else
+ if (git_buf_len(buf) != 0) {
+ giterr_set(GITERR_NET, "Unexpected EOF");
+ return p->error = -1;
+ } else {
return 0;
+ }
}
git_buf_put(buf, data, len);
@@ -28,23 +30,29 @@ int git_protocol_store_refs(git_protocol *p, const char *data, size_t len)
while (1) {
git_pkt *pkt;
- if (buf->size == 0)
+ if (git_buf_len(buf) == 0)
return 0;
- error = git_pkt_parse_line(&pkt, ptr, &line_end, buf->size);
+ error = git_pkt_parse_line(&pkt, ptr, &line_end, git_buf_len(buf));
if (error == GIT_ESHORTBUFFER)
return 0; /* Ask for more */
- if (error < GIT_SUCCESS)
- return p->error = git__rethrow(error, "Failed to parse pkt-line");
+ if (error < 0)
+ return p->error = -1;
git_buf_consume(buf, line_end);
- error = git_vector_insert(refs, pkt);
- if (error < GIT_SUCCESS)
- return p->error = git__rethrow(error, "Failed to add pkt to list");
+
+ if (pkt->type == GIT_PKT_ERR) {
+ giterr_set(GITERR_NET, "Remote error: %s", ((git_pkt_err *)pkt)->error);
+ git__free(pkt);
+ return -1;
+ }
+
+ if (git_vector_insert(refs, pkt) < 0)
+ return p->error = -1;
if (pkt->type == GIT_PKT_FLUSH)
p->flush = 1;
}
- return error;
+ return 0;
}