VcsCommand: Fix unblocking GlobalFileChangeBlocker on abort

Change-Id: Ied60a0ecb291e50f4c48dc2e5df3371e4010932e
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Jarek Kobus
2022-08-26 15:03:22 +02:00
parent 3dc3870475
commit 84426350d4

View File

@@ -64,6 +64,7 @@ public:
, m_environment(environment)
{
VcsBase::setProcessEnvironment(&m_environment);
m_futureInterface.setProgressRange(0, 1);
}
~VcsCommandPrivate() { delete m_progressParser; }
@@ -81,6 +82,8 @@ public:
QString displayName() const;
int timeoutS() const;
void setup();
void cleanup();
void setupProcess(QtcProcess *process, const Job &job);
void setupSynchronous(QtcProcess *process);
bool isFullySynchronous() const;
@@ -134,6 +137,31 @@ int VcsCommandPrivate::timeoutS() const
[](int sum, const Job &job) { return sum + job.timeoutS; });
}
void VcsCommandPrivate::setup()
{
m_futureInterface.reportStarted();
if (m_flags & VcsCommand::ExpectRepoChanges) {
QMetaObject::invokeMethod(GlobalFileChangeBlocker::instance(), [] {
GlobalFileChangeBlocker::instance()->forceBlocked(true);
});
}
if (m_progressParser)
m_progressParser->setFuture(&m_futureInterface);
}
void VcsCommandPrivate::cleanup()
{
QTC_ASSERT(m_futureInterface.isRunning(), return);
m_futureInterface.reportFinished();
if (m_flags & VcsCommand::ExpectRepoChanges) {
QMetaObject::invokeMethod(GlobalFileChangeBlocker::instance(), [] {
GlobalFileChangeBlocker::instance()->forceBlocked(false);
});
}
if (m_progressParser)
m_progressParser->setFuture(nullptr);
}
void VcsCommandPrivate::setupProcess(QtcProcess *process, const Job &job)
{
process->setExitCodeInterpreter(job.exitCodeInterpreter);
@@ -205,16 +233,7 @@ void VcsCommandPrivate::startAll()
// Check that the binary path is not empty
QTC_ASSERT(!m_jobs.isEmpty(), return);
QTC_ASSERT(!m_process, return);
m_futureInterface.reportStarted();
if (m_flags & VcsCommand::ExpectRepoChanges) {
QMetaObject::invokeMethod(this, [] {
GlobalFileChangeBlocker::instance()->forceBlocked(true);
});
}
if (m_progressParser)
m_progressParser->setFuture(&m_futureInterface);
else
m_futureInterface.setProgressRange(0, 1);
setup();
m_currentJob = 0;
startNextJob();
}
@@ -242,14 +261,8 @@ void VcsCommandPrivate::processDone()
startNextJob();
return;
}
if (m_flags & VcsCommand::ExpectRepoChanges) {
QMetaObject::invokeMethod(this, [] {
GlobalFileChangeBlocker::instance()->forceBlocked(false);
});
}
if (m_aborted) {
m_futureInterface.reportCanceled();
m_futureInterface.reportFinished();
} else {
if (!m_progressiveOutput) {
emit q->stdOutText(m_stdOut);
@@ -259,10 +272,8 @@ void VcsCommandPrivate::processDone()
emit q->finished(success);
if (!success)
m_futureInterface.reportCanceled();
m_futureInterface.reportFinished();
}
if (m_progressParser)
m_progressParser->setFuture(nullptr);
cleanup();
// As it is used asynchronously, we need to delete ourselves
q->deleteLater();
}
@@ -304,7 +315,7 @@ VcsCommand::~VcsCommand()
{
if (d->m_futureInterface.isRunning()) {
d->m_futureInterface.reportCanceled();
d->m_futureInterface.reportFinished();
d->cleanup();
}
delete d;
}