Gerrit: Improve server encapsulation

Change-Id: If78fa05e0b328a86e699ba79673999650b05a7ef
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Orgad Shaneh
2017-02-23 12:54:20 +02:00
committed by Orgad Shaneh
parent 71c2352e4b
commit da3f9379c1
3 changed files with 41 additions and 33 deletions

View File

@@ -230,8 +230,6 @@ void GerritDialog::updateRemotes()
if (m_repository.isEmpty() || !QFileInfo(m_repository).isDir())
return;
m_updatingRemotes = true;
static const QRegularExpression sshPattern(
"^(?:(?<protocol>[^:]+)://)?(?:(?<user>[^@]+)@)?(?<host>[^:/]+)(?::(?<port>\\d+))?");
*m_server = m_parameters->server;
QString errorMessage; // Mute errors. We'll just fallback to the defaults
QMap<QString, QString> remotesList =
@@ -239,35 +237,14 @@ void GerritDialog::updateRemotes()
QMapIterator<QString, QString> mapIt(remotesList);
while (mapIt.hasNext()) {
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;
QRegularExpressionMatch match = sshPattern.match(r);
if (match.hasMatch()) {
const QString protocol = match.captured("protocol");
if (protocol == "https")
server.type = GerritServer::Https;
else if (protocol == "http")
server.type = GerritServer::Http;
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());
}
if (!server.fillFromRemote(mapIt.value(), m_parameters->server.user))
continue;
// 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"));
m_updatingRemotes = false;
@@ -276,9 +253,6 @@ void GerritDialog::updateRemotes()
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) {
const GerritServer s = m_ui->remoteComboBox->itemData(i).value<GerritServer>();
if (s.host == server.host)