diff options
| author | Philip Kelley <phkelley@hotmail.com> | 2012-11-28 11:42:37 -0500 |
|---|---|---|
| committer | Philip Kelley <phkelley@hotmail.com> | 2012-11-28 11:42:37 -0500 |
| commit | 613d5eb9391d6cc33c91f4dc9cdb5ede1885dc72 (patch) | |
| tree | bd94a2a5ea154a3849114575368b7531f0d45024 /src/remote.c | |
| parent | 693021262ba0eeac2923bbce1b2262717019c807 (diff) | |
| download | libgit2-613d5eb9391d6cc33c91f4dc9cdb5ede1885dc72.tar.gz | |
Push! By schu, phkelley, and congyiwu, et al
Diffstat (limited to 'src/remote.c')
| -rw-r--r-- | src/remote.c | 79 |
1 files changed, 69 insertions, 10 deletions
diff --git a/src/remote.c b/src/remote.c index bdec3c1f4..c84911aa1 100644 --- a/src/remote.c +++ b/src/remote.c @@ -488,13 +488,13 @@ int git_remote_connect(git_remote *remote, git_direction direction) /* A transport could have been supplied in advance with * git_remote_set_transport */ - if (!t && git_transport_new(&t, url) < 0) + if (!t && git_transport_new(&t, remote, url) < 0) return -1; if (t->set_callbacks && t->set_callbacks(t, remote->callbacks.progress, NULL, remote->callbacks.payload) < 0) goto on_error; - + if (!remote->check_cert) flags |= GIT_TRANSPORTFLAGS_NO_CHECK_CERT; @@ -507,6 +507,10 @@ int git_remote_connect(git_remote *remote, git_direction direction) on_error: t->free(t); + + if (t == remote->transport) + remote->transport = NULL; + return -1; } @@ -514,7 +518,7 @@ int git_remote_ls(git_remote *remote, git_headlist_cb list_cb, void *payload) { assert(remote); - if (!remote->transport) { + if (!git_remote_connected(remote)) { giterr_set(GITERR_NET, "The remote is not connected"); return -1; } @@ -522,6 +526,63 @@ int git_remote_ls(git_remote *remote, git_headlist_cb list_cb, void *payload) return remote->transport->ls(remote->transport, list_cb, payload); } +int git_remote__get_http_proxy(git_remote *remote, bool use_ssl, char **proxy_url) +{ + git_config *cfg; + const char *val; + + assert(remote); + + if (!proxy_url) + return -1; + + *proxy_url = NULL; + + if (git_repository_config__weakptr(&cfg, remote->repo) < 0) + return -1; + + /* Go through the possible sources for proxy configuration, from most specific + * to least specific. */ + + /* remote.<name>.proxy config setting */ + if (remote->name && 0 != *(remote->name)) { + git_buf buf = GIT_BUF_INIT; + + if (git_buf_printf(&buf, "remote.%s.proxy", remote->name) < 0) + return -1; + + if (!git_config_get_string(&val, cfg, git_buf_cstr(&buf)) && + val && ('\0' != *val)) { + git_buf_free(&buf); + + *proxy_url = git__strdup(val); + GITERR_CHECK_ALLOC(*proxy_url); + return 0; + } + + git_buf_free(&buf); + } + + /* http.proxy config setting */ + if (!git_config_get_string(&val, cfg, "http.proxy") && + val && ('\0' != *val)) { + *proxy_url = git__strdup(val); + GITERR_CHECK_ALLOC(*proxy_url); + return 0; + } + + /* HTTP_PROXY / HTTPS_PROXY environment variables */ + val = use_ssl ? getenv("HTTPS_PROXY") : getenv("HTTP_PROXY"); + + if (val && ('\0' != *val)) { + *proxy_url = git__strdup(val); + GITERR_CHECK_ALLOC(*proxy_url); + return 0; + } + + return 0; +} + int git_remote_download( git_remote *remote, git_transfer_progress_callback progress_cb, @@ -687,7 +748,7 @@ int git_remote_update_tips(git_remote *remote) git_vector_init(&update_heads, 16, NULL) < 0) return -1; - if (remote->transport->ls(remote->transport, update_tips_callback, &refs) < 0) + if (git_remote_ls(remote, update_tips_callback, &refs) < 0) goto on_error; /* Let's go find HEAD, if it exists. Check only the first ref in the vector. */ @@ -779,22 +840,20 @@ on_error: int git_remote_connected(git_remote *remote) { - int connected; - assert(remote); if (!remote->transport || !remote->transport->is_connected) return 0; /* Ask the transport if it's connected. */ - remote->transport->is_connected(remote->transport, &connected); - - return connected; + return remote->transport->is_connected(remote->transport); } void git_remote_stop(git_remote *remote) { - if (remote->transport->cancel) + assert(remote); + + if (remote->transport && remote->transport->cancel) remote->transport->cancel(remote->transport); } |
