diff options
author | Andre Hartmann <aha_1980@gmx.de> | 2017-03-09 19:13:38 +0100 |
---|---|---|
committer | André Hartmann <aha_1980@gmx.de> | 2017-03-09 22:02:30 +0000 |
commit | b0ac6435b3786854e7a8d10cf4d8df49ca74618a (patch) | |
tree | cf053a90e07a5c7623c42fd05de3f426c65927b9 /src/plugins/git/gerrit/gerritserver.cpp | |
parent | 6e7d2a40014a012f52bcfa776c5ca50b15ea2420 (diff) | |
download | qt-creator-b0ac6435b3786854e7a8d10cf4d8df49ca74618a.tar.gz |
Git: Add new class GitRemote
Allows to split a remote URL and performs
some validation checks on the elements.
Change-Id: I048373076b1a1553fdd7bed2986a41cc087138b0
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Diffstat (limited to 'src/plugins/git/gerrit/gerritserver.cpp')
-rw-r--r-- | src/plugins/git/gerrit/gerritserver.cpp | 32 |
1 files changed, 10 insertions, 22 deletions
diff --git a/src/plugins/git/gerrit/gerritserver.cpp b/src/plugins/git/gerrit/gerritserver.cpp index 1c2e8807a4..3c8d028fdf 100644 --- a/src/plugins/git/gerrit/gerritserver.cpp +++ b/src/plugins/git/gerrit/gerritserver.cpp @@ -113,39 +113,27 @@ QString GerritServer::url(UrlType urlType) const bool GerritServer::fillFromRemote(const QString &remote, const GerritParameters ¶meters) { - static const QRegularExpression remotePattern( - "^(?:(?<protocol>[^:]+)://)?(?:(?<user>[^@]+)@)?(?<host>[^:/]+)" - "(?::(?<port>\\d+))?:?(?<path>/.*)$"); - - // 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 (HostOsInfo::isWindowsHost() && remote[1] == ':') - return false; - QRegularExpressionMatch match = remotePattern.match(remote); - if (!match.hasMatch()) + const GitRemote r(remote); + if (!r.isValid) return false; - const QString protocol = match.captured("protocol"); - if (protocol == "https") + + if (r.protocol == "https") type = GerritServer::Https; - else if (protocol == "http") + else if (r.protocol == "http") type = GerritServer::Http; - else if (protocol.isEmpty() || protocol == "ssh") + else if (r.protocol.isEmpty() || r.protocol == "ssh") type = GerritServer::Ssh; else return false; - const QString userName = match.captured("user"); - user.userName = userName.isEmpty() ? parameters.server.user.userName : userName; - host = match.captured("host"); - port = match.captured("port").toUShort(); - if (host.contains("github.com")) // Clearly not gerrit + + user.userName = r.userName.isEmpty() ? parameters.server.user.userName : r.userName; + if (r.host.contains("github.com")) // Clearly not gerrit return false; if (type != GerritServer::Ssh) { curlBinary = parameters.curl; if (curlBinary.isEmpty() || !QFile::exists(curlBinary)) return false; - rootPath = match.captured("path"); + rootPath = r.path; // Strip the last part of the path, which is always the repo name // The rest of the path needs to be inspected to find the root path // (can be http://example.net/review) |