summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOrgad Shaneh <orgad.shaneh@audiocodes.com>2017-02-23 12:54:20 +0200
committerOrgad Shaneh <orgads@gmail.com>2017-02-23 12:14:57 +0000
commitda3f9379c1c945c61c80dbaeb17f3919e4c0a779 (patch)
treec0fad7686072dead86d5796c734cd77fa005fa3b
parent71c2352e4b4cafcfb228139db406d0ec8e3160d1 (diff)
downloadqt-creator-da3f9379c1c945c61c80dbaeb17f3919e4c0a779.tar.gz
Gerrit: Improve server encapsulation
Change-Id: If78fa05e0b328a86e699ba79673999650b05a7ef Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
-rw-r--r--src/plugins/git/gerrit/gerritdialog.cpp40
-rw-r--r--src/plugins/git/gerrit/gerritparameters.cpp33
-rw-r--r--src/plugins/git/gerrit/gerritparameters.h1
3 files changed, 41 insertions, 33 deletions
diff --git a/src/plugins/git/gerrit/gerritdialog.cpp b/src/plugins/git/gerrit/gerritdialog.cpp
index 78b8bbd36d..43f71b50c4 100644
--- a/src/plugins/git/gerrit/gerritdialog.cpp
+++ b/src/plugins/git/gerrit/gerritdialog.cpp
@@ -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)
diff --git a/src/plugins/git/gerrit/gerritparameters.cpp b/src/plugins/git/gerrit/gerritparameters.cpp
index 8796e580c1..a1e5ef8b57 100644
--- a/src/plugins/git/gerrit/gerritparameters.cpp
+++ b/src/plugins/git/gerrit/gerritparameters.cpp
@@ -31,6 +31,7 @@
#include <QDebug>
#include <QFileInfo>
+#include <QRegularExpression>
#include <QSettings>
#include <QStandardPaths>
@@ -118,6 +119,38 @@ QString GerritServer::url() const
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
{
return server == rhs.server && ssh == rhs.ssh && https == rhs.https;
diff --git a/src/plugins/git/gerrit/gerritparameters.h b/src/plugins/git/gerrit/gerritparameters.h
index 7e66a9a574..90ed6fd80c 100644
--- a/src/plugins/git/gerrit/gerritparameters.h
+++ b/src/plugins/git/gerrit/gerritparameters.h
@@ -47,6 +47,7 @@ public:
bool operator==(const GerritServer &other) const;
QString sshHostArgument() const;
QString url() const;
+ bool fillFromRemote(const QString &remote, const QString &defaultUser);
QString host;
QString user;