mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 23:13:25 +00:00
Cloud storage: Setup http proxy for git connection
At the time of this commit support for this feature has not landed in upstream libgit2, yet (but there is a pull request). Yet supporting this here doesn't appear to cause any issue with older versions of libgit2, either, so the http proxy support will simply not work when enabled and a version of libgit2 that's too old is used. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
3ff3577eda
commit
490d21806e
2 changed files with 33 additions and 6 deletions
22
git-access.c
22
git-access.c
|
@ -215,12 +215,17 @@ static int check_remote_status(git_repository *repo, git_remote *origin, const c
|
|||
git_reference_free(remote_ref);
|
||||
}
|
||||
|
||||
/* from qthelper.cpp */
|
||||
extern bool getProxyString(char **proxy_string);
|
||||
|
||||
static git_repository *update_local_repo(const char *localdir, const char *remote, const char *branch)
|
||||
{
|
||||
int error;
|
||||
git_repository *repo = NULL;
|
||||
git_remote *origin;
|
||||
enum remote_type rt;
|
||||
char *proxy_string;
|
||||
git_config *conf;
|
||||
|
||||
error = git_repository_open(&repo, localdir);
|
||||
if (error) {
|
||||
|
@ -228,7 +233,18 @@ static git_repository *update_local_repo(const char *localdir, const char *remot
|
|||
localdir, giterr_last()->message);
|
||||
return NULL;
|
||||
}
|
||||
if (strncmp(remote, "ssh://", 6) == 0)
|
||||
rt = SSH;
|
||||
else if (strncmp(remote, "https://", 8) == 0)
|
||||
rt = HTTPS;
|
||||
else
|
||||
rt = OTHER;
|
||||
|
||||
if (rt == HTTPS && getProxyString(&proxy_string)) {
|
||||
git_repository_config(&conf, repo);
|
||||
git_config_set_string(conf, "http.proxy", proxy_string);
|
||||
free(proxy_string);
|
||||
}
|
||||
/*
|
||||
* NOTE! Remote errors are reported, but are nonfatal:
|
||||
* we still successfully return the local repository.
|
||||
|
@ -240,12 +256,6 @@ static git_repository *update_local_repo(const char *localdir, const char *remot
|
|||
return repo;
|
||||
}
|
||||
|
||||
if (strncmp(remote, "ssh://", 6) == 0)
|
||||
rt = SSH;
|
||||
else if (strncmp(remote, "https://", 8) == 0)
|
||||
rt = HTTPS;
|
||||
else
|
||||
rt = OTHER;
|
||||
#if USE_LIBGIT23_API
|
||||
git_fetch_options opts = GIT_FETCH_OPTIONS_INIT;
|
||||
if (rt == SSH)
|
||||
|
|
17
qthelper.cpp
17
qthelper.cpp
|
@ -24,6 +24,7 @@
|
|||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkProxy>
|
||||
#include <QUrlQuery>
|
||||
#include <QEventLoop>
|
||||
#include <QDateTime>
|
||||
|
@ -1034,3 +1035,19 @@ int getCloudURL(QString &filename)
|
|||
filename = QString("https://cloud.subsurface-divelog.org/git/%1[%1]").arg(email);
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" bool getProxyString(char **buffer)
|
||||
{
|
||||
if (prefs.proxy_type == QNetworkProxy::HttpProxy) {
|
||||
QString proxy;
|
||||
if (prefs.proxy_auth)
|
||||
proxy = QString("http://%1:%2@%3:%4").arg(prefs.proxy_user).arg(prefs.proxy_pass)
|
||||
.arg(prefs.proxy_host).arg(prefs.proxy_port);
|
||||
else
|
||||
proxy = QString("http://%1:%2").arg(prefs.proxy_host).arg(prefs.proxy_port);
|
||||
if (buffer)
|
||||
*buffer = strdup(qPrintable(proxy));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue