forked from qt-creator/qt-creator
Git: Proliferate FilePath use in GerritModel a bit
Plus some code cosmetics. Change-Id: Idc07e881c09cbc7347396ef1bb60cce00539250c Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include "pathchooser.h"
|
#include "pathchooser.h"
|
||||||
|
|
||||||
|
#include "commandline.h"
|
||||||
#include "environment.h"
|
#include "environment.h"
|
||||||
#include "hostosinfo.h"
|
#include "hostosinfo.h"
|
||||||
#include "macroexpander.h"
|
#include "macroexpander.h"
|
||||||
@@ -718,9 +719,9 @@ FancyLineEdit *PathChooser::lineEdit() const
|
|||||||
return d->m_lineEdit;
|
return d->m_lineEdit;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PathChooser::toolVersion(const QString &binary, const QStringList &arguments)
|
QString PathChooser::toolVersion(const CommandLine &cmd)
|
||||||
{
|
{
|
||||||
return BinaryVersionToolTipEventFilter::toolVersion({FilePath::fromString(binary), arguments});
|
return BinaryVersionToolTipEventFilter::toolVersion(cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PathChooser::installLineEditVersionToolTip(QLineEdit *le, const QStringList &arguments)
|
void PathChooser::installLineEditVersionToolTip(QLineEdit *le, const QStringList &arguments)
|
||||||
|
@@ -38,6 +38,7 @@ QT_END_NAMESPACE
|
|||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
|
class CommandLine;
|
||||||
class FancyLineEdit;
|
class FancyLineEdit;
|
||||||
class MacroExpander;
|
class MacroExpander;
|
||||||
class Environment;
|
class Environment;
|
||||||
@@ -124,7 +125,7 @@ public:
|
|||||||
void setCommandVersionArguments(const QStringList &arguments);
|
void setCommandVersionArguments(const QStringList &arguments);
|
||||||
|
|
||||||
// Utility to run a tool and return its stdout.
|
// Utility to run a tool and return its stdout.
|
||||||
static QString toolVersion(const QString &binary, const QStringList &arguments);
|
static QString toolVersion(const Utils::CommandLine &cmd);
|
||||||
// Install a tooltip on lineedits used for binaries showing the version.
|
// Install a tooltip on lineedits used for binaries showing the version.
|
||||||
static void installLineEditVersionToolTip(QLineEdit *le, const QStringList &arguments);
|
static void installLineEditVersionToolTip(QLineEdit *le, const QStringList &arguments);
|
||||||
|
|
||||||
|
@@ -251,9 +251,9 @@ private:
|
|||||||
|
|
||||||
void errorTermination(const QString &msg);
|
void errorTermination(const QString &msg);
|
||||||
|
|
||||||
Utils::QtcProcess m_process;
|
QtcProcess m_process;
|
||||||
QTimer m_timer;
|
QTimer m_timer;
|
||||||
QString m_binary;
|
FilePath m_binary;
|
||||||
QByteArray m_output;
|
QByteArray m_output;
|
||||||
QString m_error;
|
QString m_error;
|
||||||
QFutureInterface<void> m_progress;
|
QFutureInterface<void> m_progress;
|
||||||
@@ -321,10 +321,9 @@ void QueryContext::start()
|
|||||||
fp->setKeepOnFinish(Core::FutureProgress::HideOnFinish);
|
fp->setKeepOnFinish(Core::FutureProgress::HideOnFinish);
|
||||||
m_progress.reportStarted();
|
m_progress.reportStarted();
|
||||||
// Order: synchronous call to error handling if something goes wrong.
|
// Order: synchronous call to error handling if something goes wrong.
|
||||||
VcsOutputWindow::appendCommand(m_process.workingDirectory(),
|
VcsOutputWindow::appendCommand(m_process.workingDirectory(), {m_binary, m_arguments});
|
||||||
{FilePath::fromString(m_binary), m_arguments});
|
|
||||||
m_timer.start();
|
m_timer.start();
|
||||||
m_process.setCommand({FilePath::fromString(m_binary), m_arguments});
|
m_process.setCommand({m_binary, m_arguments});
|
||||||
m_process.start();
|
m_process.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -344,7 +343,7 @@ void QueryContext::terminate()
|
|||||||
|
|
||||||
void QueryContext::processError(QProcess::ProcessError e)
|
void QueryContext::processError(QProcess::ProcessError e)
|
||||||
{
|
{
|
||||||
const QString msg = tr("Error running %1: %2").arg(m_binary, m_process.errorString());
|
const QString msg = tr("Error running %1: %2").arg(m_binary.toUserOutput(), m_process.errorString());
|
||||||
if (e == QProcess::FailedToStart)
|
if (e == QProcess::FailedToStart)
|
||||||
errorTermination(msg);
|
errorTermination(msg);
|
||||||
else
|
else
|
||||||
@@ -357,10 +356,10 @@ void QueryContext::processFinished()
|
|||||||
m_timer.stop();
|
m_timer.stop();
|
||||||
emit errorText(m_error);
|
emit errorText(m_error);
|
||||||
if (m_process.exitStatus() != QProcess::NormalExit) {
|
if (m_process.exitStatus() != QProcess::NormalExit) {
|
||||||
errorTermination(tr("%1 crashed.").arg(m_binary));
|
errorTermination(tr("%1 crashed.").arg(m_binary.toUserOutput()));
|
||||||
return;
|
return;
|
||||||
} else if (m_process.exitCode()) {
|
} else if (m_process.exitCode()) {
|
||||||
errorTermination(tr("%1 returned %2.").arg(m_binary).arg(m_process.exitCode()));
|
errorTermination(tr("%1 returned %2.").arg(m_binary.toUserOutput()).arg(m_process.exitCode()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
emit resultRetrieved(m_output);
|
emit resultRetrieved(m_output);
|
||||||
|
@@ -124,8 +124,8 @@ GerritParameters GerritOptionsWidget::parameters() const
|
|||||||
static_cast<unsigned short>(m_portSpinBox->value()),
|
static_cast<unsigned short>(m_portSpinBox->value()),
|
||||||
m_userLineEdit->text().trimmed(),
|
m_userLineEdit->text().trimmed(),
|
||||||
GerritServer::Ssh);
|
GerritServer::Ssh);
|
||||||
result.ssh = m_sshChooser->filePath().toString();
|
result.ssh = m_sshChooser->filePath();
|
||||||
result.curl = m_curlChooser->filePath().toString();
|
result.curl = m_curlChooser->filePath();
|
||||||
result.https = m_httpsCheckBox->isChecked();
|
result.https = m_httpsCheckBox->isChecked();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -134,8 +134,8 @@ void GerritOptionsWidget::setParameters(const GerritParameters &p)
|
|||||||
{
|
{
|
||||||
m_hostLineEdit->setText(p.server.host);
|
m_hostLineEdit->setText(p.server.host);
|
||||||
m_userLineEdit->setText(p.server.user.userName);
|
m_userLineEdit->setText(p.server.user.userName);
|
||||||
m_sshChooser->setPath(p.ssh);
|
m_sshChooser->setFilePath(p.ssh);
|
||||||
m_curlChooser->setPath(p.curl);
|
m_curlChooser->setFilePath(p.curl);
|
||||||
m_portSpinBox->setValue(p.server.port);
|
m_portSpinBox->setValue(p.server.port);
|
||||||
m_httpsCheckBox->setChecked(p.https);
|
m_httpsCheckBox->setChecked(p.https);
|
||||||
}
|
}
|
||||||
|
@@ -26,6 +26,7 @@
|
|||||||
#include "gerritparameters.h"
|
#include "gerritparameters.h"
|
||||||
#include "gerritplugin.h"
|
#include "gerritplugin.h"
|
||||||
|
|
||||||
|
#include <utils/commandline.h>
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
#include <utils/pathchooser.h>
|
#include <utils/pathchooser.h>
|
||||||
|
|
||||||
@@ -38,52 +39,51 @@ using namespace Utils;
|
|||||||
namespace Gerrit {
|
namespace Gerrit {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
static const char settingsGroupC[] = "Gerrit";
|
const char settingsGroupC[] = "Gerrit";
|
||||||
static const char hostKeyC[] = "Host";
|
const char hostKeyC[] = "Host";
|
||||||
static const char userKeyC[] = "User";
|
const char userKeyC[] = "User";
|
||||||
static const char portKeyC[] = "Port";
|
const char portKeyC[] = "Port";
|
||||||
static const char portFlagKeyC[] = "PortFlag";
|
const char portFlagKeyC[] = "PortFlag";
|
||||||
static const char sshKeyC[] = "Ssh";
|
const char sshKeyC[] = "Ssh";
|
||||||
static const char curlKeyC[] = "Curl";
|
const char curlKeyC[] = "Curl";
|
||||||
static const char httpsKeyC[] = "Https";
|
const char httpsKeyC[] = "Https";
|
||||||
static const char savedQueriesKeyC[] = "SavedQueries";
|
const char savedQueriesKeyC[] = "SavedQueries";
|
||||||
|
|
||||||
static const char defaultPortFlag[] = "-p";
|
const char defaultPortFlag[] = "-p";
|
||||||
|
|
||||||
static inline QString detectApp(const char *defaultExe)
|
static FilePath detectApp(const QString &defaultExe)
|
||||||
{
|
{
|
||||||
const QString defaultApp = HostOsInfo::withExecutableSuffix(QLatin1String(defaultExe));
|
const QString defaultApp = HostOsInfo::withExecutableSuffix(defaultExe);
|
||||||
QString app = QStandardPaths::findExecutable(defaultApp);
|
const QString app = QStandardPaths::findExecutable(defaultApp);
|
||||||
if (!app.isEmpty() || !HostOsInfo::isWindowsHost())
|
if (!app.isEmpty() || !HostOsInfo::isWindowsHost())
|
||||||
return app;
|
return FilePath::fromString(app);
|
||||||
// Windows: Use app.exe from git if it cannot be found.
|
// Windows: Use app.exe from git if it cannot be found.
|
||||||
const FilePath gitBinDir = GerritPlugin::gitBinDirectory();
|
const FilePath gitBinDir = GerritPlugin::gitBinDirectory();
|
||||||
if (gitBinDir.isEmpty())
|
if (gitBinDir.isEmpty())
|
||||||
return QString();
|
return {};
|
||||||
FilePath path = gitBinDir.pathAppended(defaultApp);
|
FilePath path = gitBinDir.pathAppended(defaultApp);
|
||||||
if (path.exists())
|
if (path.exists())
|
||||||
return path.toString();
|
return path;
|
||||||
|
|
||||||
// If app was not found, and git bin is Git/usr/bin (Git for Windows),
|
// If app was not found, and git bin is Git/usr/bin (Git for Windows),
|
||||||
// search also in Git/mingw{32,64}/bin
|
// search also in Git/mingw{32,64}/bin
|
||||||
if (!gitBinDir.endsWith("/usr/bin"))
|
if (!gitBinDir.endsWith("/usr/bin"))
|
||||||
return QString();
|
return {};
|
||||||
path = gitBinDir.parentDir().parentDir();
|
path = gitBinDir.parentDir().parentDir();
|
||||||
QDir dir(path.toString());
|
const FilePaths entries = path.dirEntries({"mingw*"}, {});
|
||||||
const QStringList entries = dir.entryList({"mingw*"});
|
|
||||||
if (entries.isEmpty())
|
if (entries.isEmpty())
|
||||||
return QString();
|
return {};
|
||||||
path = path / entries.first() / "bin" / defaultApp;
|
path = entries.first() / "bin" / defaultApp;
|
||||||
if (path.exists())
|
if (path.exists())
|
||||||
return path.toString();
|
return path;
|
||||||
return QString();
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline QString detectSsh()
|
static FilePath detectSsh()
|
||||||
{
|
{
|
||||||
const QByteArray gitSsh = qgetenv("GIT_SSH");
|
const QString gitSsh = qEnvironmentVariable("GIT_SSH");
|
||||||
if (!gitSsh.isEmpty())
|
if (!gitSsh.isEmpty())
|
||||||
return QString::fromLocal8Bit(gitSsh);
|
return FilePath::fromString(gitSsh);
|
||||||
return detectApp("ssh");
|
return detectApp("ssh");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ void GerritParameters::setPortFlagBySshType()
|
|||||||
{
|
{
|
||||||
bool isPlink = false;
|
bool isPlink = false;
|
||||||
if (!ssh.isEmpty()) {
|
if (!ssh.isEmpty()) {
|
||||||
const QString version = PathChooser::toolVersion(ssh, {"-V"});
|
const QString version = PathChooser::toolVersion({ssh, {"-V"}});
|
||||||
isPlink = version.contains("plink", Qt::CaseInsensitive);
|
isPlink = version.contains("plink", Qt::CaseInsensitive);
|
||||||
}
|
}
|
||||||
portFlag = QLatin1String(isPlink ? "-P" : defaultPortFlag);
|
portFlag = QLatin1String(isPlink ? "-P" : defaultPortFlag);
|
||||||
@@ -114,8 +114,8 @@ void GerritParameters::toSettings(QSettings *s) const
|
|||||||
s->setValue(userKeyC, server.user.userName);
|
s->setValue(userKeyC, server.user.userName);
|
||||||
s->setValue(portKeyC, server.port);
|
s->setValue(portKeyC, server.port);
|
||||||
s->setValue(portFlagKeyC, portFlag);
|
s->setValue(portFlagKeyC, portFlag);
|
||||||
s->setValue(sshKeyC, ssh);
|
s->setValue(sshKeyC, ssh.toVariant());
|
||||||
s->setValue(curlKeyC, curl);
|
s->setValue(curlKeyC, curl.toVariant());
|
||||||
s->setValue(httpsKeyC, https);
|
s->setValue(httpsKeyC, https);
|
||||||
s->endGroup();
|
s->endGroup();
|
||||||
}
|
}
|
||||||
@@ -132,16 +132,16 @@ void GerritParameters::fromSettings(const QSettings *s)
|
|||||||
const QString rootKey = QLatin1String(settingsGroupC) + '/';
|
const QString rootKey = QLatin1String(settingsGroupC) + '/';
|
||||||
server.host = s->value(rootKey + hostKeyC, GerritServer::defaultHost()).toString();
|
server.host = s->value(rootKey + hostKeyC, GerritServer::defaultHost()).toString();
|
||||||
server.user.userName = s->value(rootKey + userKeyC, QString()).toString();
|
server.user.userName = s->value(rootKey + userKeyC, QString()).toString();
|
||||||
ssh = s->value(rootKey + sshKeyC, QString()).toString();
|
ssh = FilePath::fromVariant(s->value(rootKey + sshKeyC, QString()));
|
||||||
curl = s->value(rootKey + curlKeyC).toString();
|
curl = FilePath::fromVariant(s->value(rootKey + curlKeyC));
|
||||||
server.port = ushort(s->value(rootKey + portKeyC, QVariant(GerritServer::defaultPort)).toInt());
|
server.port = ushort(s->value(rootKey + portKeyC, QVariant(GerritServer::defaultPort)).toInt());
|
||||||
portFlag = s->value(rootKey + portFlagKeyC, defaultPortFlag).toString();
|
portFlag = s->value(rootKey + portFlagKeyC, defaultPortFlag).toString();
|
||||||
savedQueries = s->value(rootKey + savedQueriesKeyC, QString()).toString()
|
savedQueries = s->value(rootKey + savedQueriesKeyC, QString()).toString()
|
||||||
.split(',');
|
.split(',');
|
||||||
https = s->value(rootKey + httpsKeyC, QVariant(true)).toBool();
|
https = s->value(rootKey + httpsKeyC, QVariant(true)).toBool();
|
||||||
if (ssh.isEmpty() || !QFile::exists(ssh))
|
if (ssh.isEmpty() || !ssh.exists())
|
||||||
ssh = detectSsh();
|
ssh = detectSsh();
|
||||||
if (curl.isEmpty() || !QFile::exists(curl))
|
if (curl.isEmpty() || !curl.exists())
|
||||||
curl = detectApp("curl");
|
curl = detectApp("curl");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -27,7 +27,7 @@
|
|||||||
|
|
||||||
#include "gerritserver.h"
|
#include "gerritserver.h"
|
||||||
|
|
||||||
#include <QStringList>
|
#include <utils/filepath.h>
|
||||||
|
|
||||||
QT_FORWARD_DECLARE_CLASS(QSettings)
|
QT_FORWARD_DECLARE_CLASS(QSettings)
|
||||||
|
|
||||||
@@ -47,8 +47,8 @@ public:
|
|||||||
void setPortFlagBySshType();
|
void setPortFlagBySshType();
|
||||||
|
|
||||||
GerritServer server;
|
GerritServer server;
|
||||||
QString ssh;
|
Utils::FilePath ssh;
|
||||||
QString curl;
|
Utils::FilePath curl;
|
||||||
QStringList savedQueries;
|
QStringList savedQueries;
|
||||||
bool https = true;
|
bool https = true;
|
||||||
QString portFlag;
|
QString portFlag;
|
||||||
|
@@ -161,7 +161,7 @@ bool GerritServer::fillFromRemote(const QString &remote,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
curlBinary = parameters.curl;
|
curlBinary = parameters.curl;
|
||||||
if (curlBinary.isEmpty() || !QFile::exists(curlBinary))
|
if (curlBinary.isEmpty() || !curlBinary.exists())
|
||||||
return false;
|
return false;
|
||||||
const StoredHostValidity validity = forceReload ? Invalid : loadSettings();
|
const StoredHostValidity validity = forceReload ? Invalid : loadSettings();
|
||||||
switch (validity) {
|
switch (validity) {
|
||||||
@@ -245,7 +245,7 @@ int GerritServer::testConnection()
|
|||||||
static GitClient *const client = GitClient::instance();
|
static GitClient *const client = GitClient::instance();
|
||||||
const QStringList arguments = curlArguments() << (url(RestUrl) + accountUrlC);
|
const QStringList arguments = curlArguments() << (url(RestUrl) + accountUrlC);
|
||||||
QtcProcess proc;
|
QtcProcess proc;
|
||||||
client->vcsFullySynchronousExec(proc, {}, {FilePath::fromString(curlBinary), arguments},
|
client->vcsFullySynchronousExec(proc, {}, {curlBinary, arguments},
|
||||||
Core::ShellCommand::NoOutput);
|
Core::ShellCommand::NoOutput);
|
||||||
if (proc.result() == QtcProcess::FinishedWithSuccess) {
|
if (proc.result() == QtcProcess::FinishedWithSuccess) {
|
||||||
QString output = proc.stdOut();
|
QString output = proc.stdOut();
|
||||||
@@ -346,15 +346,14 @@ void GerritServer::resolveVersion(const GerritParameters &p, bool forceReload)
|
|||||||
if (port)
|
if (port)
|
||||||
arguments << p.portFlag << QString::number(port);
|
arguments << p.portFlag << QString::number(port);
|
||||||
arguments << hostArgument() << "gerrit" << "version";
|
arguments << hostArgument() << "gerrit" << "version";
|
||||||
client->vcsFullySynchronousExec(proc, {}, {FilePath::fromString(p.ssh), arguments},
|
client->vcsFullySynchronousExec(proc, {}, {p.ssh, arguments}, Core::ShellCommand::NoOutput);
|
||||||
Core::ShellCommand::NoOutput);
|
|
||||||
QString stdOut = proc.stdOut().trimmed();
|
QString stdOut = proc.stdOut().trimmed();
|
||||||
stdOut.remove("gerrit version ");
|
stdOut.remove("gerrit version ");
|
||||||
version = stdOut;
|
version = stdOut;
|
||||||
} else {
|
} else {
|
||||||
const QStringList arguments = curlArguments() << (url(RestUrl) + versionUrlC);
|
const QStringList arguments = curlArguments() << (url(RestUrl) + versionUrlC);
|
||||||
QtcProcess proc;
|
QtcProcess proc;
|
||||||
client->vcsFullySynchronousExec(proc, {}, {FilePath::fromString(curlBinary), arguments},
|
client->vcsFullySynchronousExec(proc, {}, {curlBinary, arguments},
|
||||||
Core::ShellCommand::NoOutput);
|
Core::ShellCommand::NoOutput);
|
||||||
// REST endpoint for version is only available from 2.8 and up. Do not consider invalid
|
// REST endpoint for version is only available from 2.8 and up. Do not consider invalid
|
||||||
// if it fails.
|
// if it fails.
|
||||||
|
@@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QStringList>
|
#include <utils/filepath.h>
|
||||||
|
|
||||||
namespace Gerrit {
|
namespace Gerrit {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -88,7 +88,7 @@ public:
|
|||||||
bool validateCert = true;
|
bool validateCert = true;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString curlBinary;
|
Utils::FilePath curlBinary;
|
||||||
StoredHostValidity loadSettings();
|
StoredHostValidity loadSettings();
|
||||||
void saveSettings(StoredHostValidity validity) const;
|
void saveSettings(StoredHostValidity validity) const;
|
||||||
bool setupAuthentication();
|
bool setupAuthentication();
|
||||||
|
Reference in New Issue
Block a user