forked from qt-creator/qt-creator
Fixes: add timeout value to git plugin
RevBy: tba Details: - as on windows some git commands take much longer it happens fairly often, that git timeouts. - added a timeout value to the option to let the user choose maximum timeout value (minimum is 10 seconds, maximum 5 minutes)
This commit is contained in:
@@ -207,20 +207,20 @@ void GitClient::diff(const QString &workingDirectory,
|
|||||||
QStringList arguments;
|
QStringList arguments;
|
||||||
arguments << QLatin1String("diff") << diffArgs;
|
arguments << QLatin1String("diff") << diffArgs;
|
||||||
m_plugin->outputWindow()->append(formatCommand(binary, arguments));
|
m_plugin->outputWindow()->append(formatCommand(binary, arguments));
|
||||||
command->addJob(arguments);
|
command->addJob(arguments, m_settings.timeout);
|
||||||
} else {
|
} else {
|
||||||
// Files diff.
|
// Files diff.
|
||||||
if (!unstagedFileNames.empty()) {
|
if (!unstagedFileNames.empty()) {
|
||||||
QStringList arguments;
|
QStringList arguments;
|
||||||
arguments << QLatin1String("diff") << diffArgs << QLatin1String("--") << unstagedFileNames;
|
arguments << QLatin1String("diff") << diffArgs << QLatin1String("--") << unstagedFileNames;
|
||||||
m_plugin->outputWindow()->append(formatCommand(binary, arguments));
|
m_plugin->outputWindow()->append(formatCommand(binary, arguments));
|
||||||
command->addJob(arguments);
|
command->addJob(arguments, m_settings.timeout);
|
||||||
}
|
}
|
||||||
if (!stagedFileNames.empty()) {
|
if (!stagedFileNames.empty()) {
|
||||||
QStringList arguments;
|
QStringList arguments;
|
||||||
arguments << QLatin1String("diff") << QLatin1String("--cached") << diffArgs << QLatin1String("--") << stagedFileNames;
|
arguments << QLatin1String("diff") << QLatin1String("--cached") << diffArgs << QLatin1String("--") << stagedFileNames;
|
||||||
m_plugin->outputWindow()->append(formatCommand(binary, arguments));
|
m_plugin->outputWindow()->append(formatCommand(binary, arguments));
|
||||||
command->addJob(arguments);
|
command->addJob(arguments, m_settings.timeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
command->execute();
|
command->execute();
|
||||||
@@ -503,7 +503,7 @@ void GitClient::executeGit(const QString &workingDirectory,
|
|||||||
{
|
{
|
||||||
m_plugin->outputWindow()->append(formatCommand(QLatin1String(Constants::GIT_BINARY), arguments));
|
m_plugin->outputWindow()->append(formatCommand(QLatin1String(Constants::GIT_BINARY), arguments));
|
||||||
GitCommand *command = createCommand(workingDirectory, editor, outputToWindow);
|
GitCommand *command = createCommand(workingDirectory, editor, outputToWindow);
|
||||||
command->addJob(arguments);
|
command->addJob(arguments, m_settings.timeout);
|
||||||
command->execute();
|
command->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -55,8 +55,9 @@ static inline QStringList environmentToList(const ProjectExplorer::Environment &
|
|||||||
return ProjectExplorer::Environment::systemEnvironment().toStringList();
|
return ProjectExplorer::Environment::systemEnvironment().toStringList();
|
||||||
}
|
}
|
||||||
|
|
||||||
GitCommand::Job::Job(const QStringList &a) :
|
GitCommand::Job::Job(const QStringList &a, int t) :
|
||||||
arguments(a)
|
arguments(a),
|
||||||
|
timeout(t)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,9 +68,9 @@ GitCommand::GitCommand(const QString &workingDirectory,
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void GitCommand::addJob(const QStringList &arguments)
|
void GitCommand::addJob(const QStringList &arguments, int timeout)
|
||||||
{
|
{
|
||||||
m_jobs.push_back(Job(arguments));
|
m_jobs.push_back(Job(arguments, timeout));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GitCommand::execute()
|
void GitCommand::execute()
|
||||||
@@ -109,7 +110,7 @@ void GitCommand::run()
|
|||||||
qDebug() << "GitCommand::run" << j << '/' << count << m_jobs.at(j).arguments;
|
qDebug() << "GitCommand::run" << j << '/' << count << m_jobs.at(j).arguments;
|
||||||
|
|
||||||
process.start(QLatin1String(Constants::GIT_BINARY), m_jobs.at(j).arguments);
|
process.start(QLatin1String(Constants::GIT_BINARY), m_jobs.at(j).arguments);
|
||||||
if (!process.waitForFinished()) {
|
if (!process.waitForFinished(m_jobs.at(j).timeout * 1000)) {
|
||||||
ok = false;
|
ok = false;
|
||||||
error += QLatin1String("Error: Git timed out");
|
error += QLatin1String("Error: Git timed out");
|
||||||
break;
|
break;
|
||||||
|
@@ -49,7 +49,7 @@ public:
|
|||||||
ProjectExplorer::Environment &environment);
|
ProjectExplorer::Environment &environment);
|
||||||
|
|
||||||
|
|
||||||
void addJob(const QStringList &arguments);
|
void addJob(const QStringList &arguments, int timeout);
|
||||||
void execute();
|
void execute();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -61,9 +61,10 @@ Q_SIGNALS:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
struct Job {
|
struct Job {
|
||||||
explicit Job(const QStringList &a);
|
explicit Job(const QStringList &a, int t);
|
||||||
|
|
||||||
QStringList arguments;
|
QStringList arguments;
|
||||||
|
int timeout;
|
||||||
};
|
};
|
||||||
|
|
||||||
QStringList environment() const;
|
QStringList environment() const;
|
||||||
|
@@ -40,15 +40,17 @@ static const char *groupC = "Git";
|
|||||||
static const char *sysEnvKeyC = "SysEnv";
|
static const char *sysEnvKeyC = "SysEnv";
|
||||||
static const char *pathKeyC = "Path";
|
static const char *pathKeyC = "Path";
|
||||||
static const char *logCountKeyC = "LogCount";
|
static const char *logCountKeyC = "LogCount";
|
||||||
|
static const char *timeoutKeyC = "TimeOut";
|
||||||
|
|
||||||
enum { defaultLogCount = 10 };
|
enum { defaultLogCount = 10 , defaultTimeOut = 30};
|
||||||
|
|
||||||
namespace Git {
|
namespace Git {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
GitSettings::GitSettings() :
|
GitSettings::GitSettings() :
|
||||||
adoptPath(false),
|
adoptPath(false),
|
||||||
logCount(defaultLogCount)
|
logCount(defaultLogCount),
|
||||||
|
timeout(defaultTimeOut)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,6 +60,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();
|
||||||
settings->endGroup();
|
settings->endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,12 +70,13 @@ 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->endGroup();
|
settings->endGroup();
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -56,6 +56,7 @@ struct GitSettings
|
|||||||
bool adoptPath;
|
bool adoptPath;
|
||||||
QString path;
|
QString path;
|
||||||
int logCount;
|
int logCount;
|
||||||
|
int timeout;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool operator==(const GitSettings &p1, const GitSettings &p2)
|
inline bool operator==(const GitSettings &p1, const GitSettings &p2)
|
||||||
|
@@ -52,6 +52,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();
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,6 +61,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SettingsPageWidget::setSystemPath()
|
void SettingsPageWidget::setSystemPath()
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>403</width>
|
<width>403</width>
|
||||||
<height>183</height>
|
<height>251</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
@@ -69,10 +69,14 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QFormLayout" name="logFormLayout">
|
<layout class="QFormLayout" name="formLayout">
|
||||||
<property name="fieldGrowthPolicy">
|
<item row="0" column="0">
|
||||||
<enum>QFormLayout::ExpandingFieldsGrow</enum>
|
<widget class="QLabel" name="logCountLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>Log commit display count:</string>
|
||||||
</property>
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QSpinBox" name="logCountSpinBox">
|
<widget class="QSpinBox" name="logCountSpinBox">
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
@@ -83,10 +87,23 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QLabel" name="logCountLabel">
|
<widget class="QLabel" name="timeoutLabel">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Log commit display count:</string>
|
<string>Timeout (seconds):</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QSpinBox" name="timeoutSpinBox">
|
||||||
|
<property name="minimum">
|
||||||
|
<number>10</number>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>300</number>
|
||||||
|
</property>
|
||||||
|
<property name="value">
|
||||||
|
<number>30</number>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
Reference in New Issue
Block a user