Gerrit: Replace bool argument with an enum, and merge url getters

Change-Id: I82035b37de31830f26297944ea0fce8b898201a4
Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
Orgad Shaneh
2017-03-02 08:37:56 +02:00
committed by Orgad Shaneh
parent 45ffa75054
commit 45a84ea6b5
3 changed files with 19 additions and 17 deletions

View File

@@ -200,8 +200,9 @@ QString GerritChange::filterString() const
QStringList GerritChange::gitFetchArguments(const GerritServer &server) const QStringList GerritChange::gitFetchArguments(const GerritServer &server) const
{ {
const QString url = currentPatchSet.url.isEmpty() ? server.url(true) + '/' + project const QString url = currentPatchSet.url.isEmpty()
: currentPatchSet.url; ? server.url(GerritServer::UrlWithHttpUser) + '/' + project
: currentPatchSet.url;
return {"fetch", url, currentPatchSet.ref}; return {"fetch", url, currentPatchSet.ref};
} }
@@ -271,7 +272,7 @@ QueryContext::QueryContext(const QString &query,
<< "--format=JSON" << query; << "--format=JSON" << query;
} else { } else {
m_binary = p->curl; m_binary = p->curl;
const QString url = server.restUrl() + "/changes/?q=" const QString url = server.url(GerritServer::RestUrl) + "/changes/?q="
+ QString::fromUtf8(QUrl::toPercentEncoding(query)) + QString::fromUtf8(QUrl::toPercentEncoding(query))
+ "&o=CURRENT_REVISION&o=DETAILED_LABELS&o=DETAILED_ACCOUNTS"; + "&o=CURRENT_REVISION&o=DETAILED_LABELS&o=DETAILED_ACCOUNTS";
m_arguments = GerritServer::curlArguments() << url; m_arguments = GerritServer::curlArguments() << url;

View File

@@ -152,7 +152,7 @@ QString GerritServer::hostArgument() const
return user.userName.isEmpty() ? host : (user.userName + '@' + host); return user.userName.isEmpty() ? host : (user.userName + '@' + host);
} }
QString GerritServer::url(bool withHttpUser) const QString GerritServer::url(UrlType urlType) const
{ {
QString protocol; QString protocol;
switch (type) { switch (type) {
@@ -161,22 +161,17 @@ QString GerritServer::url(bool withHttpUser) const
case Https: protocol = "https"; break; case Https: protocol = "https"; break;
} }
QString res = protocol + "://"; QString res = protocol + "://";
if (type == Ssh || withHttpUser) if (type == Ssh || urlType != DefaultUrl)
res += hostArgument(); res += hostArgument();
else else
res += host; res += host;
if (port) if (port)
res += ':' + QString::number(port); res += ':' + QString::number(port);
if (type != Ssh) if (type != Ssh) {
res += rootPath; res += rootPath;
return res; if (authenticated && urlType == RestUrl)
} res += "/a";
}
QString GerritServer::restUrl() const
{
QString res = url(true);
if (type != Ssh && authenticated)
res += "/a";
return res; return res;
} }
@@ -238,7 +233,7 @@ QStringList GerritServer::curlArguments()
int GerritServer::testConnection() int GerritServer::testConnection()
{ {
static Git::Internal::GitClient *const client = Git::Internal::GitPlugin::client(); static Git::Internal::GitClient *const client = Git::Internal::GitPlugin::client();
const QStringList arguments = curlArguments() << (restUrl() + accountUrlC); const QStringList arguments = curlArguments() << (url(RestUrl) + accountUrlC);
const SynchronousProcessResponse resp = client->vcsFullySynchronousExec( const SynchronousProcessResponse resp = client->vcsFullySynchronousExec(
QString(), FileName::fromString(curlBinary), arguments, QString(), FileName::fromString(curlBinary), arguments,
Core::ShellCommand::NoOutput); Core::ShellCommand::NoOutput);

View File

@@ -54,12 +54,18 @@ public:
Ssh Ssh
}; };
enum UrlType
{
DefaultUrl,
UrlWithHttpUser,
RestUrl
};
GerritServer(); GerritServer();
GerritServer(const QString &host, unsigned short port, const QString &userName, HostType type); GerritServer(const QString &host, unsigned short port, const QString &userName, HostType type);
bool operator==(const GerritServer &other) const; bool operator==(const GerritServer &other) const;
QString hostArgument() const; QString hostArgument() const;
QString url(bool withHttpUser = false) const; QString url(UrlType urlType = DefaultUrl) const;
QString restUrl() const;
bool fillFromRemote(const QString &remote, const GerritParameters &parameters); bool fillFromRemote(const QString &remote, const GerritParameters &parameters);
int testConnection(); int testConnection();
static QStringList curlArguments(); static QStringList curlArguments();