Gerrit: Support cancel in fetch context

Task-number: QTCREATORBUG-9743
Change-Id: Idf77d1d4efa5accb1aa00f61f495a3813704c934
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: Tobias Hunger <tobias.hunger@theqtcompany.com>
This commit is contained in:
Orgad Shaneh
2015-02-04 23:59:50 +02:00
committed by Orgad Shaneh
parent c6ccb096d6
commit 10f36eada5

View File

@@ -67,6 +67,7 @@
#include <QTemporaryFile>
#include <QDir>
#include <QMap>
#include <QFutureWatcher>
using namespace Core;
using namespace Git::Internal;
@@ -126,6 +127,7 @@ private:
void show();
void cherryPick();
void checkout();
void terminate();
const QSharedPointer<GerritChange> m_change;
const QString m_repository;
@@ -135,6 +137,7 @@ private:
State m_state;
QProcess m_process;
QFutureInterface<void> m_progress;
QFutureWatcher<void> m_watcher;
};
FetchContext::FetchContext(const QSharedPointer<GerritChange> &change,
@@ -157,6 +160,9 @@ FetchContext::FetchContext(const QSharedPointer<GerritChange> &change,
this, SLOT(processReadyReadStandardError()));
connect(&m_process, SIGNAL(readyReadStandardOutput()),
this, SLOT(processReadyReadStandardOutput()));
connect(&m_watcher, &QFutureWatcher<void>::canceled,
this, &FetchContext::terminate);
m_watcher.setFuture(m_progress.future());
m_process.setWorkingDirectory(repository);
m_process.setProcessEnvironment(gitClient()->processEnvironment());
m_process.closeWriteChannel();
@@ -167,7 +173,7 @@ FetchContext::~FetchContext()
if (m_progress.isRunning())
m_progress.reportFinished();
m_process.disconnect(this);
Utils::SynchronousProcess::stopProcess(m_process);
terminate();
}
void FetchContext::start()
@@ -228,6 +234,7 @@ void FetchContext::processReadyReadStandardOutput()
void FetchContext::handleError(const QString &e)
{
m_state = ErrorState;
if (!m_progress.isCanceled())
VcsBase::VcsOutputWindow::appendError(e);
m_progress.reportCanceled();
m_progress.reportFinished();
@@ -236,6 +243,8 @@ void FetchContext::handleError(const QString &e)
void FetchContext::processError(QProcess::ProcessError e)
{
if (m_progress.isCanceled())
return;
const QString msg = tr("Error running %1: %2").arg(m_git.toUserOutput(), m_process.errorString());
if (e == QProcess::FailedToStart)
handleError(msg);
@@ -263,6 +272,11 @@ void FetchContext::checkout()
gitClient()->stashAndCheckout(m_repository, QLatin1String("FETCH_HEAD"));
}
void FetchContext::terminate()
{
Utils::SynchronousProcess::stopProcess(m_process);
}
GerritPlugin::GerritPlugin(QObject *parent)
: QObject(parent)