forked from qt-creator/qt-creator
VCS: Do less when command is aborted internally
If the user cancels a command, output and error text might still be interesting. When aborting a command internally (when Creator is closed, or later when a command is re-executed for the same editor), we don't want any of those, and they have a destructive potential. Change-Id: I5e35fdf59c0fcdc0af45f13ac142da31edf18bd7 Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
6d7bf0f7e7
commit
8e90640edb
@@ -104,6 +104,7 @@ public:
|
|||||||
bool m_progressiveOutput;
|
bool m_progressiveOutput;
|
||||||
bool m_hadOutput;
|
bool m_hadOutput;
|
||||||
bool m_preventRepositoryChanged;
|
bool m_preventRepositoryChanged;
|
||||||
|
bool m_aborted;
|
||||||
QFutureWatcher<void> m_watcher;
|
QFutureWatcher<void> m_watcher;
|
||||||
|
|
||||||
QList<Job> m_jobs;
|
QList<Job> m_jobs;
|
||||||
@@ -127,6 +128,7 @@ CommandPrivate::CommandPrivate(const QString &binary,
|
|||||||
m_progressiveOutput(false),
|
m_progressiveOutput(false),
|
||||||
m_hadOutput(false),
|
m_hadOutput(false),
|
||||||
m_preventRepositoryChanged(false),
|
m_preventRepositoryChanged(false),
|
||||||
|
m_aborted(false),
|
||||||
m_lastExecSuccess(false),
|
m_lastExecSuccess(false),
|
||||||
m_lastExecExitCode(-1)
|
m_lastExecExitCode(-1)
|
||||||
{
|
{
|
||||||
@@ -229,6 +231,12 @@ void Command::execute()
|
|||||||
Core::Id::fromString(binary + QLatin1String(".action")));
|
Core::Id::fromString(binary + QLatin1String(".action")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Command::abort()
|
||||||
|
{
|
||||||
|
d->m_aborted = true;
|
||||||
|
d->m_watcher.future().cancel();
|
||||||
|
}
|
||||||
|
|
||||||
void Command::cancel()
|
void Command::cancel()
|
||||||
{
|
{
|
||||||
emit terminate();
|
emit terminate();
|
||||||
@@ -277,14 +285,8 @@ void Command::run(QFutureInterface<void> &future)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString canceledMessage = tr("Canceled");
|
if (!d->m_aborted) {
|
||||||
if (d->m_progressiveOutput) {
|
if (!d->m_progressiveOutput) {
|
||||||
if (!d->m_hadOutput && future.isCanceled())
|
|
||||||
emit output(canceledMessage);
|
|
||||||
} else {
|
|
||||||
if (stdOut.isEmpty() && future.isCanceled())
|
|
||||||
emit output(canceledMessage);
|
|
||||||
else
|
|
||||||
emit output(stdOut);
|
emit output(stdOut);
|
||||||
if (!stdErr.isEmpty())
|
if (!stdErr.isEmpty())
|
||||||
emit errorText(stdErr);
|
emit errorText(stdErr);
|
||||||
@@ -294,6 +296,7 @@ void Command::run(QFutureInterface<void> &future)
|
|||||||
if (d->m_lastExecSuccess)
|
if (d->m_lastExecSuccess)
|
||||||
emit success(cookie());
|
emit success(cookie());
|
||||||
future.setProgressValue(future.progressMaximum());
|
future.setProgressValue(future.progressMaximum());
|
||||||
|
}
|
||||||
|
|
||||||
if (d->m_progressParser)
|
if (d->m_progressParser)
|
||||||
d->m_progressParser->setFuture(0);
|
d->m_progressParser->setFuture(0);
|
||||||
@@ -420,6 +423,7 @@ Utils::SynchronousProcessResponse Command::runVcs(const QStringList &arguments,
|
|||||||
response = process.run(d->m_binaryPath, arguments);
|
response = process.run(d->m_binaryPath, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!d->m_aborted) {
|
||||||
// Success/Fail message in appropriate window?
|
// Success/Fail message in appropriate window?
|
||||||
if (response.result == Utils::SynchronousProcessResponse::Finished) {
|
if (response.result == Utils::SynchronousProcessResponse::Finished) {
|
||||||
if (d->m_flags & VcsBasePlugin::ShowSuccessMessage)
|
if (d->m_flags & VcsBasePlugin::ShowSuccessMessage)
|
||||||
@@ -427,6 +431,7 @@ Utils::SynchronousProcessResponse Command::runVcs(const QStringList &arguments,
|
|||||||
} else if (!(d->m_flags & VcsBasePlugin::SuppressFailMessageInLogWindow)) {
|
} else if (!(d->m_flags & VcsBasePlugin::SuppressFailMessageInLogWindow)) {
|
||||||
emit outputProxy.appendError(response.exitMessage(d->m_binaryPath, timeoutMS));
|
emit outputProxy.appendError(response.exitMessage(d->m_binaryPath, timeoutMS));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
emitRepositoryChanged();
|
emitRepositoryChanged();
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
@@ -467,6 +472,7 @@ Utils::SynchronousProcessResponse Command::runSynchronous(const QStringList &arg
|
|||||||
!Utils::SynchronousProcess::readDataFromProcess(*process.data(), timeoutMS,
|
!Utils::SynchronousProcess::readDataFromProcess(*process.data(), timeoutMS,
|
||||||
&stdOut, &stdErr, true);
|
&stdOut, &stdErr, true);
|
||||||
|
|
||||||
|
if (!d->m_aborted) {
|
||||||
OutputProxy outputProxy;
|
OutputProxy outputProxy;
|
||||||
if (!stdErr.isEmpty()) {
|
if (!stdErr.isEmpty()) {
|
||||||
response.stdErr = Utils::SynchronousProcess::normalizeNewlines(
|
response.stdErr = Utils::SynchronousProcess::normalizeNewlines(
|
||||||
@@ -485,6 +491,7 @@ Utils::SynchronousProcessResponse Command::runSynchronous(const QStringList &arg
|
|||||||
emit outputProxy.append(response.stdOut);
|
emit outputProxy.append(response.stdOut);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Utils::ExitCodeInterpreter defaultInterpreter(this);
|
Utils::ExitCodeInterpreter defaultInterpreter(this);
|
||||||
Utils::ExitCodeInterpreter *currentInterpreter = interpreter ? interpreter : &defaultInterpreter;
|
Utils::ExitCodeInterpreter *currentInterpreter = interpreter ? interpreter : &defaultInterpreter;
|
||||||
@@ -570,7 +577,7 @@ void Command::bufferedError(const QString &text)
|
|||||||
void Command::coreAboutToClose()
|
void Command::coreAboutToClose()
|
||||||
{
|
{
|
||||||
d->m_preventRepositoryChanged = true;
|
d->m_preventRepositoryChanged = true;
|
||||||
cancel();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
const QVariant &Command::cookie() const
|
const QVariant &Command::cookie() const
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ public:
|
|||||||
void addJob(const QStringList &arguments, Utils::ExitCodeInterpreter *interpreter = 0);
|
void addJob(const QStringList &arguments, Utils::ExitCodeInterpreter *interpreter = 0);
|
||||||
void addJob(const QStringList &arguments, int timeout, Utils::ExitCodeInterpreter *interpreter = 0);
|
void addJob(const QStringList &arguments, int timeout, Utils::ExitCodeInterpreter *interpreter = 0);
|
||||||
void execute();
|
void execute();
|
||||||
|
void abort();
|
||||||
bool lastExecutionSuccess() const;
|
bool lastExecutionSuccess() const;
|
||||||
int lastExecutionExitCode() const;
|
int lastExecutionExitCode() const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user