Git-Raw
view release on metacpan or search on metacpan
deps/libgit2/src/libgit2/remote.c view on Meta::CPAN
if ((error = git_net_url_dup(&lookup_url, url)) < 0)
goto done;
if (remote->repo) {
if ((error = git_repository_config(&cfg, remote->repo)) < 0)
goto done;
} else {
if ((error = git_config_open_default(&cfg)) < 0)
goto done;
}
/* remote.<name>.proxy config setting */
if (remote->name && remote->name[0]) {
git_str_clear(&buf);
if ((error = git_str_printf(&buf, "remote.%s.proxy", remote->name)) < 0 ||
(error = lookup_config(out, cfg, buf.ptr)) != GIT_ENOTFOUND)
goto done;
}
while (true) {
git_str_clear(&buf);
if ((error = git_str_puts(&buf, "http.")) < 0 ||
(error = git_net_url_fmt(&buf, &lookup_url)) < 0 ||
(error = git_str_puts(&buf, ".proxy")) < 0 ||
(error = lookup_config(out, cfg, buf.ptr)) != GIT_ENOTFOUND)
goto done;
if (! lookup_url.path[0])
break;
url_config_trim(&lookup_url);
}
git_str_clear(&buf);
error = lookup_config(out, cfg, "http.proxy");
done:
git_config_free(cfg);
git_str_dispose(&buf);
git_net_url_dispose(&lookup_url);
return error;
}
static int http_proxy_env(char **out, git_remote *remote, git_net_url *url)
{
git_str proxy_env = GIT_STR_INIT, no_proxy_env = GIT_STR_INIT;
bool use_ssl = (strcmp(url->scheme, "https") == 0);
int error;
GIT_UNUSED(remote);
/* http_proxy / https_proxy environment variables */
error = git__getenv(&proxy_env, use_ssl ? "https_proxy" : "http_proxy");
/* try uppercase environment variables */
if (error == GIT_ENOTFOUND)
error = git__getenv(&proxy_env, use_ssl ? "HTTPS_PROXY" : "HTTP_PROXY");
if (error)
goto done;
/* no_proxy/NO_PROXY environment variables */
error = git__getenv(&no_proxy_env, "no_proxy");
if (error == GIT_ENOTFOUND)
error = git__getenv(&no_proxy_env, "NO_PROXY");
if (error && error != GIT_ENOTFOUND)
goto done;
if (!git_net_url_matches_pattern_list(url, no_proxy_env.ptr))
*out = git_str_detach(&proxy_env);
else
error = GIT_ENOTFOUND;
done:
git_str_dispose(&proxy_env);
git_str_dispose(&no_proxy_env);
return error;
}
int git_remote__http_proxy(char **out, git_remote *remote, git_net_url *url)
{
int error;
GIT_ASSERT_ARG(out);
GIT_ASSERT_ARG(remote);
*out = NULL;
/*
* Go through the possible sources for proxy configuration,
* Examine the various git config options first, then
* consult environment variables.
*/
if ((error = http_proxy_config(out, remote, url)) != GIT_ENOTFOUND ||
(error = http_proxy_env(out, remote, url)) != GIT_ENOTFOUND)
return error;
return 0;
}
/* DWIM `refspecs` based on `refs` and append the output to `out` */
static int dwim_refspecs(git_vector *out, git_vector *refspecs, git_vector *refs)
{
size_t i;
git_refspec *spec;
git_vector_foreach(refspecs, i, spec) {
if (git_refspec__dwim_one(out, spec, refs) < 0)
return -1;
}
return 0;
}
static void free_refspecs(git_vector *vec)
( run in 0.406 second using v1.01-cache-2.11-cpan-71847e10f99 )