forked from qt-creator/qt-creator
Git: Improve Timeouts.
- Observe timeout setting when running synchronous commands. - Increase Default on Windows - Stop process with terminate first (signal). Task-number: QTCREATORBUG-777
This commit is contained in:
@@ -236,20 +236,20 @@ void GitClient::diff(const QString &workingDirectory,
|
|||||||
QStringList arguments(commonDiffArgs);
|
QStringList arguments(commonDiffArgs);
|
||||||
arguments << diffArgs;
|
arguments << diffArgs;
|
||||||
VCSBase::VCSBaseOutputWindow::instance()->appendCommand(formatCommand(binary, arguments));
|
VCSBase::VCSBaseOutputWindow::instance()->appendCommand(formatCommand(binary, arguments));
|
||||||
command->addJob(arguments, m_settings.timeout);
|
command->addJob(arguments, m_settings.timeoutSeconds);
|
||||||
} else {
|
} else {
|
||||||
// Files diff.
|
// Files diff.
|
||||||
if (!unstagedFileNames.empty()) {
|
if (!unstagedFileNames.empty()) {
|
||||||
QStringList arguments(commonDiffArgs);
|
QStringList arguments(commonDiffArgs);
|
||||||
arguments << QLatin1String("--") << unstagedFileNames;
|
arguments << QLatin1String("--") << unstagedFileNames;
|
||||||
VCSBase::VCSBaseOutputWindow::instance()->appendCommand(formatCommand(binary, arguments));
|
VCSBase::VCSBaseOutputWindow::instance()->appendCommand(formatCommand(binary, arguments));
|
||||||
command->addJob(arguments, m_settings.timeout);
|
command->addJob(arguments, m_settings.timeoutSeconds);
|
||||||
}
|
}
|
||||||
if (!stagedFileNames.empty()) {
|
if (!stagedFileNames.empty()) {
|
||||||
QStringList arguments(commonDiffArgs);
|
QStringList arguments(commonDiffArgs);
|
||||||
arguments << QLatin1String("--cached") << diffArgs << QLatin1String("--") << stagedFileNames;
|
arguments << QLatin1String("--cached") << diffArgs << QLatin1String("--") << stagedFileNames;
|
||||||
VCSBase::VCSBaseOutputWindow::instance()->appendCommand(formatCommand(binary, arguments));
|
VCSBase::VCSBaseOutputWindow::instance()->appendCommand(formatCommand(binary, arguments));
|
||||||
command->addJob(arguments, m_settings.timeout);
|
command->addJob(arguments, m_settings.timeoutSeconds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
command->execute();
|
command->execute();
|
||||||
@@ -985,7 +985,7 @@ GitCommand *GitClient::executeGit(const QString &workingDirectory,
|
|||||||
{
|
{
|
||||||
VCSBase::VCSBaseOutputWindow::instance()->appendCommand(formatCommand(QLatin1String(Constants::GIT_BINARY), arguments));
|
VCSBase::VCSBaseOutputWindow::instance()->appendCommand(formatCommand(QLatin1String(Constants::GIT_BINARY), arguments));
|
||||||
GitCommand *command = createCommand(workingDirectory, editor, outputToWindow, editorLineNumber);
|
GitCommand *command = createCommand(workingDirectory, editor, outputToWindow, editorLineNumber);
|
||||||
command->addJob(arguments, m_settings.timeout);
|
command->addJob(arguments, m_settings.timeoutSeconds);
|
||||||
command->setTerminationReportMode(tm);
|
command->setTerminationReportMode(tm);
|
||||||
command->execute();
|
command->execute();
|
||||||
return command;
|
return command;
|
||||||
@@ -1042,10 +1042,10 @@ bool GitClient::synchronousGit(const QString &workingDirectory,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!process.waitForFinished()) {
|
if (!process.waitForFinished(m_settings.timeoutSeconds * 1000)) {
|
||||||
if (errorText)
|
if (errorText)
|
||||||
*errorText = "Error: Git timed out.";
|
*errorText = GitCommand::msgTimeout(m_settings.timeoutSeconds).toLocal8Bit();
|
||||||
process.kill();
|
GitCommand::stopProcess(process);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -112,6 +112,22 @@ void GitCommand::execute()
|
|||||||
QLatin1String("Git.action"));
|
QLatin1String("Git.action"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString GitCommand::msgTimeout(int seconds)
|
||||||
|
{
|
||||||
|
return tr("Error: Git timed out after %1s.").arg(seconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GitCommand::stopProcess(QProcess &p)
|
||||||
|
{
|
||||||
|
if (p.state() != QProcess::Running)
|
||||||
|
return true;
|
||||||
|
p.terminate();
|
||||||
|
if (p.waitForFinished(300))
|
||||||
|
return true;
|
||||||
|
p.kill();
|
||||||
|
return p.waitForFinished(300);
|
||||||
|
}
|
||||||
|
|
||||||
void GitCommand::run()
|
void GitCommand::run()
|
||||||
{
|
{
|
||||||
if (Git::Constants::debug)
|
if (Git::Constants::debug)
|
||||||
@@ -139,10 +155,11 @@ void GitCommand::run()
|
|||||||
}
|
}
|
||||||
|
|
||||||
process.closeWriteChannel();
|
process.closeWriteChannel();
|
||||||
if (!process.waitForFinished(m_jobs.at(j).timeout * 1000)) {
|
const int timeOutSeconds = m_jobs.at(j).timeout;
|
||||||
process.terminate();
|
if (!process.waitForFinished(timeOutSeconds * 1000)) {
|
||||||
|
stopProcess(process);
|
||||||
ok = false;
|
ok = false;
|
||||||
error += QLatin1String("Error: Git timed out");
|
error += msgTimeout(timeOutSeconds);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,10 @@
|
|||||||
#include <QtCore/QStringList>
|
#include <QtCore/QStringList>
|
||||||
#include <QtCore/QVariant>
|
#include <QtCore/QVariant>
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QProcess;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace Git {
|
namespace Git {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -66,6 +70,10 @@ public:
|
|||||||
TerminationReportMode reportTerminationMode() const;
|
TerminationReportMode reportTerminationMode() const;
|
||||||
void setTerminationReportMode(TerminationReportMode m);
|
void setTerminationReportMode(TerminationReportMode m);
|
||||||
|
|
||||||
|
static QString msgTimeout(int seconds);
|
||||||
|
// Helper to kill a process by SIGNAL first, allowing for cleanup
|
||||||
|
static bool stopProcess(QProcess &p);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,14 @@ static const char *promptToSubmitKeyC = "PromptForSubmit";
|
|||||||
static const char *omitAnnotationDateKeyC = "OmitAnnotationDate";
|
static const char *omitAnnotationDateKeyC = "OmitAnnotationDate";
|
||||||
static const char *spaceIgnorantBlameKeyC = "SpaceIgnorantBlame";
|
static const char *spaceIgnorantBlameKeyC = "SpaceIgnorantBlame";
|
||||||
|
|
||||||
enum { defaultLogCount = 100 , defaultTimeOut = 30};
|
enum {
|
||||||
|
defaultLogCount = 100 ,
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
defaultTimeOut = 60
|
||||||
|
#else
|
||||||
|
defaultTimeOut = 30
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
namespace Git {
|
namespace Git {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -53,7 +60,7 @@ namespace Internal {
|
|||||||
GitSettings::GitSettings() :
|
GitSettings::GitSettings() :
|
||||||
adoptPath(false),
|
adoptPath(false),
|
||||||
logCount(defaultLogCount),
|
logCount(defaultLogCount),
|
||||||
timeout(defaultTimeOut),
|
timeoutSeconds(defaultTimeOut),
|
||||||
promptToSubmit(true),
|
promptToSubmit(true),
|
||||||
omitAnnotationDate(false),
|
omitAnnotationDate(false),
|
||||||
spaceIgnorantBlame(true)
|
spaceIgnorantBlame(true)
|
||||||
@@ -66,7 +73,7 @@ void GitSettings::fromSettings(QSettings *settings)
|
|||||||
adoptPath = settings->value(QLatin1String(sysEnvKeyC), false).toBool();
|
adoptPath = settings->value(QLatin1String(sysEnvKeyC), false).toBool();
|
||||||
path = settings->value(QLatin1String(pathKeyC), QString()).toString();
|
path = settings->value(QLatin1String(pathKeyC), QString()).toString();
|
||||||
logCount = settings->value(QLatin1String(logCountKeyC), defaultLogCount).toInt();
|
logCount = settings->value(QLatin1String(logCountKeyC), defaultLogCount).toInt();
|
||||||
timeout = settings->value(QLatin1String(timeoutKeyC), defaultTimeOut).toInt();
|
timeoutSeconds = settings->value(QLatin1String(timeoutKeyC), defaultTimeOut).toInt();
|
||||||
promptToSubmit = settings->value(QLatin1String(promptToSubmitKeyC), true).toBool();
|
promptToSubmit = settings->value(QLatin1String(promptToSubmitKeyC), true).toBool();
|
||||||
omitAnnotationDate = settings->value(QLatin1String(omitAnnotationDateKeyC), false).toBool();
|
omitAnnotationDate = settings->value(QLatin1String(omitAnnotationDateKeyC), false).toBool();
|
||||||
spaceIgnorantBlame = settings->value(QLatin1String(spaceIgnorantBlameKeyC), true).toBool();
|
spaceIgnorantBlame = settings->value(QLatin1String(spaceIgnorantBlameKeyC), true).toBool();
|
||||||
@@ -79,7 +86,7 @@ void GitSettings::toSettings(QSettings *settings) const
|
|||||||
settings->setValue(QLatin1String(sysEnvKeyC), adoptPath);
|
settings->setValue(QLatin1String(sysEnvKeyC), adoptPath);
|
||||||
settings->setValue(QLatin1String(pathKeyC), path);
|
settings->setValue(QLatin1String(pathKeyC), path);
|
||||||
settings->setValue(QLatin1String(logCountKeyC), logCount);
|
settings->setValue(QLatin1String(logCountKeyC), logCount);
|
||||||
settings->setValue(QLatin1String(timeoutKeyC), timeout);
|
settings->setValue(QLatin1String(timeoutKeyC), timeoutSeconds);
|
||||||
settings->setValue(QLatin1String(promptToSubmitKeyC), promptToSubmit);
|
settings->setValue(QLatin1String(promptToSubmitKeyC), promptToSubmit);
|
||||||
settings->setValue(QLatin1String(omitAnnotationDateKeyC), omitAnnotationDate);
|
settings->setValue(QLatin1String(omitAnnotationDateKeyC), omitAnnotationDate);
|
||||||
settings->setValue(QLatin1String(spaceIgnorantBlameKeyC), spaceIgnorantBlame);
|
settings->setValue(QLatin1String(spaceIgnorantBlameKeyC), spaceIgnorantBlame);
|
||||||
@@ -89,7 +96,7 @@ void GitSettings::toSettings(QSettings *settings) const
|
|||||||
bool GitSettings::equals(const GitSettings &s) const
|
bool GitSettings::equals(const GitSettings &s) const
|
||||||
{
|
{
|
||||||
return adoptPath == s.adoptPath && path == s.path && logCount == s.logCount
|
return adoptPath == s.adoptPath && path == s.path && logCount == s.logCount
|
||||||
&& timeout == s.timeout && promptToSubmit == s.promptToSubmit
|
&& timeoutSeconds == s.timeoutSeconds && promptToSubmit == s.promptToSubmit
|
||||||
&& omitAnnotationDate == s.omitAnnotationDate && spaceIgnorantBlame == s.spaceIgnorantBlame;
|
&& omitAnnotationDate == s.omitAnnotationDate && spaceIgnorantBlame == s.spaceIgnorantBlame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ struct GitSettings
|
|||||||
bool adoptPath;
|
bool adoptPath;
|
||||||
QString path;
|
QString path;
|
||||||
int logCount;
|
int logCount;
|
||||||
int timeout;
|
int timeoutSeconds;
|
||||||
bool promptToSubmit;
|
bool promptToSubmit;
|
||||||
bool omitAnnotationDate;
|
bool omitAnnotationDate;
|
||||||
bool spaceIgnorantBlame;
|
bool spaceIgnorantBlame;
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ GitSettings SettingsPageWidget::settings() const
|
|||||||
rc.path = m_ui.pathLineEdit->text();
|
rc.path = m_ui.pathLineEdit->text();
|
||||||
rc.adoptPath = m_ui.environmentGroupBox->isChecked() && !rc.path.isEmpty();
|
rc.adoptPath = m_ui.environmentGroupBox->isChecked() && !rc.path.isEmpty();
|
||||||
rc.logCount = m_ui.logCountSpinBox->value();
|
rc.logCount = m_ui.logCountSpinBox->value();
|
||||||
rc.timeout = m_ui.timeoutSpinBox->value();
|
rc.timeoutSeconds = m_ui.timeoutSpinBox->value();
|
||||||
rc.promptToSubmit = m_ui.promptToSubmitCheckBox->isChecked();
|
rc.promptToSubmit = m_ui.promptToSubmitCheckBox->isChecked();
|
||||||
rc.omitAnnotationDate = m_ui.omitAnnotationDataCheckBox->isChecked();
|
rc.omitAnnotationDate = m_ui.omitAnnotationDataCheckBox->isChecked();
|
||||||
rc.spaceIgnorantBlame = m_ui.spaceIgnorantBlameCheckBox->isChecked();
|
rc.spaceIgnorantBlame = m_ui.spaceIgnorantBlameCheckBox->isChecked();
|
||||||
@@ -67,7 +67,7 @@ void SettingsPageWidget::setSettings(const GitSettings &s)
|
|||||||
m_ui.environmentGroupBox->setChecked(s.adoptPath);
|
m_ui.environmentGroupBox->setChecked(s.adoptPath);
|
||||||
m_ui.pathLineEdit->setText(s.path);
|
m_ui.pathLineEdit->setText(s.path);
|
||||||
m_ui.logCountSpinBox->setValue(s.logCount);
|
m_ui.logCountSpinBox->setValue(s.logCount);
|
||||||
m_ui.timeoutSpinBox->setValue(s.timeout);
|
m_ui.timeoutSpinBox->setValue(s.timeoutSeconds);
|
||||||
m_ui.promptToSubmitCheckBox->setChecked(s.promptToSubmit);
|
m_ui.promptToSubmitCheckBox->setChecked(s.promptToSubmit);
|
||||||
m_ui.omitAnnotationDataCheckBox->setChecked(s.omitAnnotationDate);
|
m_ui.omitAnnotationDataCheckBox->setChecked(s.omitAnnotationDate);
|
||||||
m_ui.spaceIgnorantBlameCheckBox->setChecked(s.spaceIgnorantBlame);
|
m_ui.spaceIgnorantBlameCheckBox->setChecked(s.spaceIgnorantBlame);
|
||||||
|
|||||||
Reference in New Issue
Block a user