Fixes: Make QtCreator fly even in face of perforce misconfiguration.

Details:  If p4 is in path, but the server isn't configured correctly we
were pretty slow, this fixes that by running p4 client -o after the
settings have changed, if that doesn't return after 2 seconds, then we
cache that as a invalid configuration.
This commit is contained in:
dt
2009-02-19 16:11:29 +01:00
parent 91707ee075
commit 469639fb3c
7 changed files with 207 additions and 85 deletions

View File

@@ -221,7 +221,6 @@ bool PerforcePlugin::initialize(const QStringList &arguments, QString *errorMess
m_coreListener = new CoreListener(this);
addObject(m_coreListener);
//register actions
Core::ActionManager *am = Core::ICore::instance()->actionManager();
@@ -682,6 +681,8 @@ void PerforcePlugin::updateActions()
bool PerforcePlugin::managesDirectory(const QString &directory) const
{
if (!checkP4Command())
return false;
const QString p4Path = directory + QLatin1String("/...");
QStringList args;
args << QLatin1String("fstat") << QLatin1String("-m1") << p4Path;
@@ -758,7 +759,7 @@ PerforceResponse PerforcePlugin::runP4Cmd(const QStringList &args,
tempfile.setAutoRemove(true);
const QChar newLine = QLatin1Char('\n');
const QChar blank = QLatin1Char(' ');
QStringList actualArgs = basicP4Args();
QStringList actualArgs = m_settings.basicP4Args();
if (!extraArgs.isEmpty()) {
if (tempfile.open()) {
QTextStream stream(&tempfile);
@@ -773,7 +774,7 @@ PerforceResponse PerforcePlugin::runP4Cmd(const QStringList &args,
actualArgs << args;
if (logFlags & CommandToWindow) {
QString command = m_settings.p4Command;
QString command = m_settings.p4Command();
command += blank;
command += actualArgs.join(QString(blank));
const QString timeStamp = QTime::currentTime().toString(QLatin1String("HH:mm"));
@@ -799,7 +800,7 @@ PerforceResponse PerforcePlugin::runP4Cmd(const QStringList &args,
connect(&process, SIGNAL(stdOutBuffered(QString,bool)), m_perforceOutputWindow, SLOT(append(QString,bool)));
}
const Core::Utils::SynchronousProcessResponse sp_resp = process.run(m_settings.p4Command, actualArgs);
const Core::Utils::SynchronousProcessResponse sp_resp = process.run(m_settings.p4Command(), actualArgs);
if (Perforce::Constants::debug)
qDebug() << sp_resp;
@@ -817,7 +818,7 @@ PerforceResponse PerforcePlugin::runP4Cmd(const QStringList &args,
response.message = tr("The process terminated abnormally.");
break;
case Core::Utils::SynchronousProcessResponse::StartFailed:
response.message = tr("Could not start perforce '%1'. Please check your settings in the preferences.").arg(m_settings.p4Command);
response.message = tr("Could not start perforce '%1'. Please check your settings in the preferences.").arg(m_settings.p4Command());
break;
case Core::Utils::SynchronousProcessResponse::Hang:
response.message = tr("Perforce did not respond within timeout limit (%1 ms).").arg(p4Timeout );
@@ -969,8 +970,8 @@ bool PerforcePlugin::editorAboutToClose(Core::IEditor *editor)
proc.setEnvironment(environment());
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
proc.start(m_settings.p4Command,
basicP4Args() << QLatin1String("submit") << QLatin1String("-i"));
proc.start(m_settings.p4Command(),
m_settings.basicP4Args() << QLatin1String("submit") << QLatin1String("-i"));
if (!proc.waitForStarted(p4Timeout)) {
showOutput(tr("Cannot execute p4 submit."), true);
QApplication::restoreOverrideCursor();
@@ -1018,8 +1019,8 @@ QString PerforcePlugin::clientFilePath(const QString &serverFilePath)
QApplication::setOverrideCursor(Qt::WaitCursor);
QProcess proc;
proc.setEnvironment(environment());
proc.start(m_settings.p4Command,
basicP4Args() << QLatin1String("fstat") << serverFilePath);
proc.start(m_settings.p4Command(),
m_settings.basicP4Args() << QLatin1String("fstat") << serverFilePath);
QString path;
if (proc.waitForFinished(3000)) {
@@ -1047,22 +1048,9 @@ QString PerforcePlugin::currentFileName()
return fileName;
}
QStringList PerforcePlugin::basicP4Args() const
{
QStringList lst;
if (!m_settings.defaultEnv) {
lst << QLatin1String("-c") << m_settings.p4Client;
lst << QLatin1String("-p") << m_settings.p4Port;
lst << QLatin1String("-u") << m_settings.p4User;
}
return lst;
}
bool PerforcePlugin::checkP4Command() const
{
if (m_settings.p4Command.isEmpty())
return false;
return true;
return m_settings.isValid();
}
QString PerforcePlugin::pendingChangesData()
@@ -1074,8 +1062,8 @@ QString PerforcePlugin::pendingChangesData()
QString user;
QProcess proc;
proc.setEnvironment(environment());
proc.start(m_settings.p4Command,
basicP4Args() << QLatin1String("info"));
proc.start(m_settings.p4Command(),
m_settings.basicP4Args() << QLatin1String("info"));
if (proc.waitForFinished(3000)) {
QString output = QString::fromUtf8(proc.readAllStandardOutput());
if (!output.isEmpty()) {
@@ -1087,8 +1075,8 @@ QString PerforcePlugin::pendingChangesData()
}
if (user.isEmpty())
return data;
proc.start(m_settings.p4Command,
basicP4Args() << QLatin1String("changes") << QLatin1String("-s") << QLatin1String("pending") << QLatin1String("-u") << user);
proc.start(m_settings.p4Command(),
m_settings.basicP4Args() << QLatin1String("changes") << QLatin1String("-s") << QLatin1String("pending") << QLatin1String("-u") << user);
if (proc.waitForFinished(3000))
data = QString::fromUtf8(proc.readAllStandardOutput());
return data;
@@ -1139,17 +1127,24 @@ PerforcePlugin::~PerforcePlugin()
}
}
PerforceSettings PerforcePlugin::settings() const
const PerforceSettings& PerforcePlugin::settings() const
{
return m_settings;
}
void PerforcePlugin::setSettings(const PerforceSettings &s)
void PerforcePlugin::setSettings(const QString &p4Command, const QString &p4Port, const QString &p4Client, const QString p4User, bool defaultEnv)
{
if (s != m_settings) {
m_settings = s;
if (QSettings *settings = Core::ICore::instance()->settings())
m_settings.toSettings(settings);
if (m_settings.p4Command() == p4Command
&& m_settings.p4Port() == p4Port
&& m_settings.p4Client() == p4Client
&& m_settings.p4User() == p4User
&& m_settings.defaultEnv() == defaultEnv)
{
// Nothing to do
} else {
m_settings.setSettings(p4Command, p4Port, p4Client, p4User, defaultEnv);
m_settings.toSettings(Core::ICore::instance()->settings());
}
}
@@ -1162,9 +1157,9 @@ QString PerforcePlugin::fileNameFromPerforceName(const QString& perforceName,
return perforceName;
// "where" remaps the file to client file tree
QProcess proc;
QStringList args(basicP4Args());
QStringList args(m_settings.basicP4Args());
args << QLatin1String("where") << perforceName;
proc.start(m_settings.p4Command, args);
proc.start(m_settings.p4Command(), args);
if (!proc.waitForFinished()) {
*errorMessage = tr("Timeout waiting for \"where\" (%1).").arg(perforceName);
return QString();