http: add a set of common refs Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
diff --git a/src/transport-http.c b/src/transport-http.c
index 269526c..3ee7b0c 100644
--- a/src/transport-http.c
+++ b/src/transport-http.c
@@ -394,8 +394,9 @@ static int http_negotiate_fetch(git_transport *transport, git_repository *repo,
unsigned int i;
char buff[128];
gitno_buffer buf;
- git_revwalk *walk;
- git_oid oid;
+ git_revwalk *walk = NULL;
+ git_oid oid, *poid;
+ git_vector common;
const char *prefix = "http://", *url = t->parent.url;
git_buf request = GIT_BUF_INIT;
gitno_buffer_setup(&buf, buff, sizeof(buff), t->socket);
@@ -404,39 +405,64 @@ static int http_negotiate_fetch(git_transport *transport, git_repository *repo,
if (!git__prefixcmp(url, prefix))
url += strlen(prefix);
- error = setup_walk(&walk, repo);
+ error = git_vector_init(&common, 16, NULL);
if (error < GIT_SUCCESS)
- return git__rethrow(error, "Failed to setup walk");
+ return git__rethrow(error, "Failed to init common vector");
+
+ error = setup_walk(&walk, repo);
+ if (error < GIT_SUCCESS) {
+ error = git__rethrow(error, "Failed to setup walk");
+ goto cleanup;
+ }
do {
error = do_connect(t, t->host, t->port);
- if (error < GIT_SUCCESS)
- return git__rethrow(error, "Failed to connect to host");
+ if (error < GIT_SUCCESS) {
+ error = git__rethrow(error, "Failed to connect to host");
+ goto cleanup;
+ }
error = gen_request(&request, url, t->host, "POST", "upload-pack");
- if (error < GIT_SUCCESS)
- return git__rethrow(error, "Failed to generate request");
+ if (error < GIT_SUCCESS) {
+ error = git__rethrow(error, "Failed to generate request");
+ goto cleanup;
+ }
error = gitno_send(t->socket, request.ptr, request.size, 0);
- if (error < GIT_SUCCESS)
- return git__rethrow(error, "Failed to send request");
+ if (error < GIT_SUCCESS) {
+ error = git__rethrow(error, "Failed to send request");
+ goto cleanup;
+ }
error = git_pkt_send_wants(wants, &t->caps, t->socket, 1);
- if (error < GIT_SUCCESS)
- return git__rethrow(error, "Failed to send wants");
+ if (error < GIT_SUCCESS) {
+ error = git__rethrow(error, "Failed to send wants");
+ goto cleanup;
+ }
+ /* We need to send these on each connection */
+ git_vector_foreach (&common, i, poid) {
+ error = git_pkt_send_have(poid, t->socket, 1);
+ if (error < GIT_SUCCESS) {
+ error = git__rethrow(error, "Failed to send common have");
+ goto cleanup;
+ }
+ }
i = 0;
while ((error = git_revwalk_next(&oid, walk)) == GIT_SUCCESS) {
error = git_pkt_send_have(&oid, t->socket, 1);
- if (error < GIT_SUCCESS)
- return git__rethrow(error, "Failed to send have");
+ if (error < GIT_SUCCESS) {
+ error = git__rethrow(error, "Failed to send have");
+ goto cleanup;
+ }
i++;
}
if (error < GIT_SUCCESS || i >= 256)
break;
} while(1);
+cleanup:
git_revwalk_free(walk);
return error;
}