forked from qt-creator/qt-creator
Gerrit: Factor out server settings
Preparing for gerrit determination by git remote. Task-number: QTCREATORBUG-8381 Change-Id: Ic862210f40124cd2fb4bb4aa125c7b8e534cd764 Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
committed by
Orgad Shaneh
parent
5035807f89
commit
2e2c3c39af
@@ -72,7 +72,7 @@ GerritDialog::GerritDialog(const QSharedPointer<GerritParameters> &p,
|
||||
, m_repositoryChooserLabel(new QLabel(tr("Apply in:") + ' ', this))
|
||||
, m_fetchRunning(false)
|
||||
{
|
||||
setWindowTitle(tr("Gerrit %1@%2").arg(p->user, p->host));
|
||||
setWindowTitle(tr("Gerrit %1@%2").arg(p->server.user, p->server.host));
|
||||
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
|
||||
QGroupBox *changesGroup = new QGroupBox(tr("Changes"));
|
||||
|
||||
@@ -87,7 +87,7 @@ QDebug operator<<(QDebug d, const GerritChange &c)
|
||||
static inline QString defaultUrl(const QSharedPointer<GerritParameters> &p, int gerritNumber)
|
||||
{
|
||||
QString result = QLatin1String(p->https ? "https://" : "http://");
|
||||
result += p->host;
|
||||
result += p->server.host;
|
||||
result += '/';
|
||||
result += QString::number(gerritNumber);
|
||||
return result;
|
||||
@@ -197,8 +197,8 @@ QString GerritChange::filterString() const
|
||||
QStringList GerritChange::gitFetchArguments(const QSharedPointer<GerritParameters> &p) const
|
||||
{
|
||||
QStringList arguments;
|
||||
const QString url = "ssh://" + p->sshHostArgument()
|
||||
+ ':' + QString::number(p->port) + '/'
|
||||
const QString url = "ssh://" + p->server.sshHostArgument()
|
||||
+ ':' + QString::number(p->server.port) + '/'
|
||||
+ project;
|
||||
arguments << "fetch" << url << currentPatchSet.ref;
|
||||
return arguments;
|
||||
@@ -258,7 +258,8 @@ QueryContext::QueryContext(const QStringList &queries,
|
||||
: QObject(parent)
|
||||
, m_queries(queries)
|
||||
, m_currentQuery(0)
|
||||
, m_baseArguments({ p->ssh, p->portFlag, QString::number(p->port), p->sshHostArgument(), "gerrit" })
|
||||
, m_baseArguments({ p->ssh, p->portFlag, QString::number(p->server.port),
|
||||
p->server.sshHostArgument(), "gerrit" })
|
||||
{
|
||||
connect(&m_process, &QProcess::readyReadStandardError,
|
||||
this, &QueryContext::readyReadStandardError);
|
||||
@@ -520,13 +521,13 @@ void GerritModel::refresh(const QString &query)
|
||||
else
|
||||
{
|
||||
const QString statusOpenQuery = "status:open";
|
||||
if (m_parameters->user.isEmpty()) {
|
||||
if (m_parameters->server.user.isEmpty()) {
|
||||
queries.push_back(statusOpenQuery);
|
||||
} else {
|
||||
// Owned by:
|
||||
queries.push_back(statusOpenQuery + " owner:" + m_parameters->user);
|
||||
queries.push_back(statusOpenQuery + " owner:" + m_parameters->server.user);
|
||||
// For Review by:
|
||||
queries.push_back(statusOpenQuery + " reviewer:" + m_parameters->user);
|
||||
queries.push_back(statusOpenQuery + " reviewer:" + m_parameters->server.user);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -110,20 +110,21 @@ GerritOptionsWidget::GerritOptionsWidget(QWidget *parent)
|
||||
GerritParameters GerritOptionsWidget::parameters() const
|
||||
{
|
||||
GerritParameters result;
|
||||
result.host = m_hostLineEdit->text().trimmed();
|
||||
result.user = m_userLineEdit->text().trimmed();
|
||||
result.server = GerritServer(m_hostLineEdit->text().trimmed(),
|
||||
static_cast<unsigned short>(m_portSpinBox->value()),
|
||||
m_userLineEdit->text().trimmed(),
|
||||
GerritServer::Ssh);
|
||||
result.ssh = m_sshChooser->path();
|
||||
result.port = m_portSpinBox->value();
|
||||
result.https = m_httpsCheckBox->isChecked();
|
||||
return result;
|
||||
}
|
||||
|
||||
void GerritOptionsWidget::setParameters(const GerritParameters &p)
|
||||
{
|
||||
m_hostLineEdit->setText(p.host);
|
||||
m_userLineEdit->setText(p.user);
|
||||
m_hostLineEdit->setText(p.server.host);
|
||||
m_userLineEdit->setText(p.server.user);
|
||||
m_sshChooser->setPath(p.ssh);
|
||||
m_portSpinBox->setValue(p.port);
|
||||
m_portSpinBox->setValue(p.server.port);
|
||||
m_httpsCheckBox->setChecked(p.https);
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,25 @@ static inline QString detectSsh()
|
||||
return ssh;
|
||||
}
|
||||
|
||||
GerritServer::GerritServer()
|
||||
: host(defaultHostC)
|
||||
, port(defaultPort)
|
||||
{
|
||||
}
|
||||
|
||||
GerritServer::GerritServer(const QString &host, unsigned short port,
|
||||
const QString &user, HostType type)
|
||||
: host(host)
|
||||
, user(user)
|
||||
, port(port)
|
||||
, type(type)
|
||||
{}
|
||||
|
||||
bool GerritServer::operator==(const GerritServer &other) const
|
||||
{
|
||||
return host == other.host && user == other.user && port == other.port && type == other.type;
|
||||
}
|
||||
|
||||
void GerritParameters::setPortFlagBySshType()
|
||||
{
|
||||
bool isPlink = false;
|
||||
@@ -79,30 +98,27 @@ void GerritParameters::setPortFlagBySshType()
|
||||
}
|
||||
|
||||
GerritParameters::GerritParameters()
|
||||
: host(defaultHostC)
|
||||
, port(defaultPort)
|
||||
, https(true)
|
||||
: https(true)
|
||||
, portFlag(defaultPortFlag)
|
||||
{
|
||||
}
|
||||
|
||||
QString GerritParameters::sshHostArgument() const
|
||||
QString GerritServer::sshHostArgument() const
|
||||
{
|
||||
return user.isEmpty() ? host : (user + '@' + host);
|
||||
}
|
||||
|
||||
bool GerritParameters::equals(const GerritParameters &rhs) const
|
||||
{
|
||||
return port == rhs.port && host == rhs.host && user == rhs.user
|
||||
&& ssh == rhs.ssh && https == rhs.https;
|
||||
return server == rhs.server && ssh == rhs.ssh && https == rhs.https;
|
||||
}
|
||||
|
||||
void GerritParameters::toSettings(QSettings *s) const
|
||||
{
|
||||
s->beginGroup(settingsGroupC);
|
||||
s->setValue(hostKeyC, host);
|
||||
s->setValue(userKeyC, user);
|
||||
s->setValue(portKeyC, port);
|
||||
s->setValue(hostKeyC, server.host);
|
||||
s->setValue(userKeyC, server.user);
|
||||
s->setValue(portKeyC, server.port);
|
||||
s->setValue(portFlagKeyC, portFlag);
|
||||
s->setValue(sshKeyC, ssh);
|
||||
s->setValue(httpsKeyC, https);
|
||||
@@ -119,10 +135,10 @@ void GerritParameters::saveQueries(QSettings *s) const
|
||||
void GerritParameters::fromSettings(const QSettings *s)
|
||||
{
|
||||
const QString rootKey = QLatin1String(settingsGroupC) + '/';
|
||||
host = s->value(rootKey + hostKeyC, defaultHostC).toString();
|
||||
user = s->value(rootKey + userKeyC, QString()).toString();
|
||||
server.host = s->value(rootKey + hostKeyC, defaultHostC).toString();
|
||||
server.user = s->value(rootKey + userKeyC, QString()).toString();
|
||||
ssh = s->value(rootKey + sshKeyC, QString()).toString();
|
||||
port = s->value(rootKey + portKeyC, QVariant(int(defaultPort))).toInt();
|
||||
server.port = s->value(rootKey + portKeyC, QVariant(int(defaultPort))).toInt();
|
||||
portFlag = s->value(rootKey + portFlagKeyC, defaultPortFlag).toString();
|
||||
savedQueries = s->value(rootKey + savedQueriesKeyC, QString()).toString()
|
||||
.split(',');
|
||||
@@ -133,7 +149,7 @@ void GerritParameters::fromSettings(const QSettings *s)
|
||||
|
||||
bool GerritParameters::isValid() const
|
||||
{
|
||||
return !host.isEmpty() && !user.isEmpty() && !ssh.isEmpty();
|
||||
return !server.host.isEmpty() && !server.user.isEmpty() && !ssh.isEmpty();
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -32,12 +32,32 @@ QT_FORWARD_DECLARE_CLASS(QSettings)
|
||||
namespace Gerrit {
|
||||
namespace Internal {
|
||||
|
||||
class GerritServer
|
||||
{
|
||||
public:
|
||||
enum HostType
|
||||
{
|
||||
Http,
|
||||
Https,
|
||||
Ssh
|
||||
};
|
||||
|
||||
GerritServer();
|
||||
GerritServer(const QString &host, unsigned short port, const QString &user, HostType type);
|
||||
bool operator==(const GerritServer &other) const;
|
||||
QString sshHostArgument() const;
|
||||
|
||||
QString host;
|
||||
QString user;
|
||||
unsigned short port = 0;
|
||||
HostType type = Ssh;
|
||||
};
|
||||
|
||||
class GerritParameters
|
||||
{
|
||||
public:
|
||||
GerritParameters();
|
||||
|
||||
QString sshHostArgument() const;
|
||||
bool isValid() const;
|
||||
bool equals(const GerritParameters &rhs) const;
|
||||
void toSettings(QSettings *) const;
|
||||
@@ -45,9 +65,7 @@ public:
|
||||
void fromSettings(const QSettings *);
|
||||
void setPortFlagBySshType();
|
||||
|
||||
QString host;
|
||||
unsigned short port;
|
||||
QString user;
|
||||
GerritServer server;
|
||||
QString ssh;
|
||||
QStringList savedQueries;
|
||||
bool https;
|
||||
|
||||
@@ -414,7 +414,7 @@ void GerritPlugin::fetch(const QSharedPointer<GerritChange> &change, int mode)
|
||||
foreach (QString remote, remotes) {
|
||||
if (remote.endsWith(".git"))
|
||||
remote.chop(4);
|
||||
if (remote.contains(m_parameters->host) && remote.endsWith(change->project)) {
|
||||
if (remote.contains(m_parameters->server.host) && remote.endsWith(change->project)) {
|
||||
verifiedRepository = true;
|
||||
break;
|
||||
}
|
||||
@@ -426,7 +426,7 @@ void GerritPlugin::fetch(const QSharedPointer<GerritChange> &change, int mode)
|
||||
QString remote = submoduleData.url;
|
||||
if (remote.endsWith(".git"))
|
||||
remote.chop(4);
|
||||
if (remote.contains(m_parameters->host) && remote.endsWith(change->project)
|
||||
if (remote.contains(m_parameters->server.host) && remote.endsWith(change->project)
|
||||
&& QFile::exists(repository + '/' + submoduleData.dir)) {
|
||||
repository = QDir::cleanPath(repository + '/' + submoduleData.dir);
|
||||
verifiedRepository = true;
|
||||
@@ -440,7 +440,7 @@ void GerritPlugin::fetch(const QSharedPointer<GerritChange> &change, int mode)
|
||||
ICore::mainWindow(), tr("Remote Not Verified"),
|
||||
tr("Change host %1\nand project %2\n\nwere not verified among remotes"
|
||||
" in %3. Select different folder?")
|
||||
.arg(m_parameters->host,
|
||||
.arg(m_parameters->server.host,
|
||||
change->project,
|
||||
QDir::toNativeSeparators(repository)),
|
||||
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
|
||||
|
||||
Reference in New Issue
Block a user