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:
Orgad Shaneh
2013-09-29 22:50:13 +03:00
committed by Orgad Shaneh
parent 6d7bf0f7e7
commit 8e90640edb
2 changed files with 45 additions and 37 deletions

View File

@@ -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,23 +285,18 @@ 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);
} }
emit finished(d->m_lastExecSuccess, d->m_lastExecExitCode, cookie()); emit finished(d->m_lastExecSuccess, d->m_lastExecExitCode, cookie());
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,12 +423,14 @@ Utils::SynchronousProcessResponse Command::runVcs(const QStringList &arguments,
response = process.run(d->m_binaryPath, arguments); response = process.run(d->m_binaryPath, arguments);
} }
// Success/Fail message in appropriate window? if (!d->m_aborted) {
if (response.result == Utils::SynchronousProcessResponse::Finished) { // Success/Fail message in appropriate window?
if (d->m_flags & VcsBasePlugin::ShowSuccessMessage) if (response.result == Utils::SynchronousProcessResponse::Finished) {
emit outputProxy.appendMessage(response.exitMessage(d->m_binaryPath, timeoutMS)); if (d->m_flags & VcsBasePlugin::ShowSuccessMessage)
} else if (!(d->m_flags & VcsBasePlugin::SuppressFailMessageInLogWindow)) { emit outputProxy.appendMessage(response.exitMessage(d->m_binaryPath, timeoutMS));
emit outputProxy.appendError(response.exitMessage(d->m_binaryPath, timeoutMS)); } else if (!(d->m_flags & VcsBasePlugin::SuppressFailMessageInLogWindow)) {
emit outputProxy.appendError(response.exitMessage(d->m_binaryPath, timeoutMS));
}
} }
emitRepositoryChanged(); emitRepositoryChanged();
@@ -467,22 +472,24 @@ 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);
OutputProxy outputProxy; if (!d->m_aborted) {
if (!stdErr.isEmpty()) { OutputProxy outputProxy;
response.stdErr = Utils::SynchronousProcess::normalizeNewlines( if (!stdErr.isEmpty()) {
d->m_codec ? d->m_codec->toUnicode(stdErr) : QString::fromLocal8Bit(stdErr)); response.stdErr = Utils::SynchronousProcess::normalizeNewlines(
if (!(d->m_flags & VcsBasePlugin::SuppressStdErrInLogWindow)) d->m_codec ? d->m_codec->toUnicode(stdErr) : QString::fromLocal8Bit(stdErr));
emit outputProxy.append(response.stdErr); if (!(d->m_flags & VcsBasePlugin::SuppressStdErrInLogWindow))
} emit outputProxy.append(response.stdErr);
}
if (!stdOut.isEmpty()) { if (!stdOut.isEmpty()) {
response.stdOut = Utils::SynchronousProcess::normalizeNewlines( response.stdOut = Utils::SynchronousProcess::normalizeNewlines(
d->m_codec ? d->m_codec->toUnicode(stdOut) : QString::fromLocal8Bit(stdOut)); d->m_codec ? d->m_codec->toUnicode(stdOut) : QString::fromLocal8Bit(stdOut));
if (d->m_flags & VcsBasePlugin::ShowStdOutInLogWindow) { if (d->m_flags & VcsBasePlugin::ShowStdOutInLogWindow) {
if (d->m_flags & VcsBasePlugin::SilentOutput) if (d->m_flags & VcsBasePlugin::SilentOutput)
emit outputProxy.appendSilently(response.stdOut); emit outputProxy.appendSilently(response.stdOut);
else else
emit outputProxy.append(response.stdOut); emit outputProxy.append(response.stdOut);
}
} }
} }
@@ -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

View File

@@ -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;