From 10f36eada5c723ac444689cf37fe1100085c2640 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Wed, 4 Feb 2015 23:59:50 +0200 Subject: [PATCH] Gerrit: Support cancel in fetch context MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Task-number: QTCREATORBUG-9743 Change-Id: Idf77d1d4efa5accb1aa00f61f495a3813704c934 Reviewed-by: Friedemann Kleint Reviewed-by: André Hartmann Reviewed-by: Tobias Hunger --- src/plugins/git/gerrit/gerritplugin.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/plugins/git/gerrit/gerritplugin.cpp b/src/plugins/git/gerrit/gerritplugin.cpp index 878b50a7dad..fa7a0b8d05b 100644 --- a/src/plugins/git/gerrit/gerritplugin.cpp +++ b/src/plugins/git/gerrit/gerritplugin.cpp @@ -67,6 +67,7 @@ #include #include #include +#include using namespace Core; using namespace Git::Internal; @@ -126,6 +127,7 @@ private: void show(); void cherryPick(); void checkout(); + void terminate(); const QSharedPointer m_change; const QString m_repository; @@ -135,6 +137,7 @@ private: State m_state; QProcess m_process; QFutureInterface m_progress; + QFutureWatcher m_watcher; }; FetchContext::FetchContext(const QSharedPointer &change, @@ -157,6 +160,9 @@ FetchContext::FetchContext(const QSharedPointer &change, this, SLOT(processReadyReadStandardError())); connect(&m_process, SIGNAL(readyReadStandardOutput()), this, SLOT(processReadyReadStandardOutput())); + connect(&m_watcher, &QFutureWatcher::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,7 +234,8 @@ void FetchContext::processReadyReadStandardOutput() void FetchContext::handleError(const QString &e) { m_state = ErrorState; - VcsBase::VcsOutputWindow::appendError(e); + if (!m_progress.isCanceled()) + VcsBase::VcsOutputWindow::appendError(e); m_progress.reportCanceled(); m_progress.reportFinished(); deleteLater(); @@ -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)