forked from qt-creator/qt-creator
Gerrit: Improve server encapsulation
Change-Id: If78fa05e0b328a86e699ba79673999650b05a7ef Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
committed by
Orgad Shaneh
parent
71c2352e4b
commit
da3f9379c1
@@ -230,8 +230,6 @@ void GerritDialog::updateRemotes()
|
|||||||
if (m_repository.isEmpty() || !QFileInfo(m_repository).isDir())
|
if (m_repository.isEmpty() || !QFileInfo(m_repository).isDir())
|
||||||
return;
|
return;
|
||||||
m_updatingRemotes = true;
|
m_updatingRemotes = true;
|
||||||
static const QRegularExpression sshPattern(
|
|
||||||
"^(?:(?<protocol>[^:]+)://)?(?:(?<user>[^@]+)@)?(?<host>[^:/]+)(?::(?<port>\\d+))?");
|
|
||||||
*m_server = m_parameters->server;
|
*m_server = m_parameters->server;
|
||||||
QString errorMessage; // Mute errors. We'll just fallback to the defaults
|
QString errorMessage; // Mute errors. We'll just fallback to the defaults
|
||||||
QMap<QString, QString> remotesList =
|
QMap<QString, QString> remotesList =
|
||||||
@@ -239,35 +237,14 @@ void GerritDialog::updateRemotes()
|
|||||||
QMapIterator<QString, QString> mapIt(remotesList);
|
QMapIterator<QString, QString> mapIt(remotesList);
|
||||||
while (mapIt.hasNext()) {
|
while (mapIt.hasNext()) {
|
||||||
mapIt.next();
|
mapIt.next();
|
||||||
const QString r = mapIt.value();
|
|
||||||
// Skip local remotes (refer to the root or relative path)
|
|
||||||
if (r.isEmpty() || r.startsWith('/') || r.startsWith('.'))
|
|
||||||
continue;
|
|
||||||
// On Windows, local paths typically starts with <drive>:
|
|
||||||
if (Utils::HostOsInfo::isWindowsHost() && r[1] == ':')
|
|
||||||
continue;
|
|
||||||
GerritServer server;
|
GerritServer server;
|
||||||
QRegularExpressionMatch match = sshPattern.match(r);
|
if (!server.fillFromRemote(mapIt.value(), m_parameters->server.user))
|
||||||
if (match.hasMatch()) {
|
continue;
|
||||||
const QString protocol = match.captured("protocol");
|
// Only Ssh is currently supported. In order to extend support for http[s],
|
||||||
if (protocol == "https")
|
// we need to move this logic to the model, and attempt connection to each
|
||||||
server.type = GerritServer::Https;
|
// remote (do it only on refresh, not on each path change)
|
||||||
else if (protocol == "http")
|
if (server.type == GerritServer::Ssh)
|
||||||
server.type = GerritServer::Http;
|
addRemote(server, mapIt.key());
|
||||||
else if (protocol.isEmpty() || protocol == "ssh")
|
|
||||||
server.type = GerritServer::Ssh;
|
|
||||||
else
|
|
||||||
continue;
|
|
||||||
const QString user = match.captured("user");
|
|
||||||
server.user = user.isEmpty() ? m_parameters->server.user : user;
|
|
||||||
server.host = match.captured("host");
|
|
||||||
server.port = match.captured("port").toUShort();
|
|
||||||
// Only Ssh is currently supported. In order to extend support for http[s],
|
|
||||||
// we need to move this logic to the model, and attempt connection to each
|
|
||||||
// remote (do it only on refresh, not on each path change)
|
|
||||||
if (server.type == GerritServer::Ssh)
|
|
||||||
addRemote(server, mapIt.key());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
addRemote(m_parameters->server, tr("Fallback"));
|
addRemote(m_parameters->server, tr("Fallback"));
|
||||||
m_updatingRemotes = false;
|
m_updatingRemotes = false;
|
||||||
@@ -276,9 +253,6 @@ void GerritDialog::updateRemotes()
|
|||||||
|
|
||||||
void GerritDialog::addRemote(const GerritServer &server, const QString &name)
|
void GerritDialog::addRemote(const GerritServer &server, const QString &name)
|
||||||
{
|
{
|
||||||
// Clearly not gerrit
|
|
||||||
if (server.host.contains("github.com"))
|
|
||||||
return;
|
|
||||||
for (int i = 0, total = m_ui->remoteComboBox->count(); i < total; ++i) {
|
for (int i = 0, total = m_ui->remoteComboBox->count(); i < total; ++i) {
|
||||||
const GerritServer s = m_ui->remoteComboBox->itemData(i).value<GerritServer>();
|
const GerritServer s = m_ui->remoteComboBox->itemData(i).value<GerritServer>();
|
||||||
if (s.host == server.host)
|
if (s.host == server.host)
|
||||||
|
@@ -31,6 +31,7 @@
|
|||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
|
#include <QRegularExpression>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
|
|
||||||
@@ -118,6 +119,38 @@ QString GerritServer::url() const
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool GerritServer::fillFromRemote(const QString &remote, const QString &defaultUser)
|
||||||
|
{
|
||||||
|
static const QRegularExpression remotePattern(
|
||||||
|
"^(?:(?<protocol>[^:]+)://)?(?:(?<user>[^@]+)@)?(?<host>[^:/]+)(?::(?<port>\\d+))?");
|
||||||
|
|
||||||
|
// Skip local remotes (refer to the root or relative path)
|
||||||
|
if (remote.isEmpty() || remote.startsWith('/') || remote.startsWith('.'))
|
||||||
|
return false;
|
||||||
|
// On Windows, local paths typically starts with <drive>:
|
||||||
|
if (Utils::HostOsInfo::isWindowsHost() && remote[1] == ':')
|
||||||
|
return false;
|
||||||
|
QRegularExpressionMatch match = remotePattern.match(remote);
|
||||||
|
if (!match.hasMatch())
|
||||||
|
return false;
|
||||||
|
const QString protocol = match.captured("protocol");
|
||||||
|
if (protocol == "https")
|
||||||
|
type = GerritServer::Https;
|
||||||
|
else if (protocol == "http")
|
||||||
|
type = GerritServer::Http;
|
||||||
|
else if (protocol.isEmpty() || protocol == "ssh")
|
||||||
|
type = GerritServer::Ssh;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
const QString userName = match.captured("user");
|
||||||
|
user = userName.isEmpty() ? defaultUser : userName;
|
||||||
|
host = match.captured("host");
|
||||||
|
port = match.captured("port").toUShort();
|
||||||
|
if (host.contains("github.com")) // Clearly not gerrit
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool GerritParameters::equals(const GerritParameters &rhs) const
|
bool GerritParameters::equals(const GerritParameters &rhs) const
|
||||||
{
|
{
|
||||||
return server == rhs.server && ssh == rhs.ssh && https == rhs.https;
|
return server == rhs.server && ssh == rhs.ssh && https == rhs.https;
|
||||||
|
@@ -47,6 +47,7 @@ public:
|
|||||||
bool operator==(const GerritServer &other) const;
|
bool operator==(const GerritServer &other) const;
|
||||||
QString sshHostArgument() const;
|
QString sshHostArgument() const;
|
||||||
QString url() const;
|
QString url() const;
|
||||||
|
bool fillFromRemote(const QString &remote, const QString &defaultUser);
|
||||||
|
|
||||||
QString host;
|
QString host;
|
||||||
QString user;
|
QString user;
|
||||||
|
Reference in New Issue
Block a user