VcsCommand: Block auto reload while a command is running

Git rebase is executed in the background, and it can change a file multiple
times in a short period. If we reparse a file while this happens on
Windows, Git fails to replace it, the rebase action fails and the
repository becomes unstable (remains with a modified file).

See discussion at https://github.com/git-for-windows/git/pull/1666

Task-number: QTCREATORBUG-15449
Change-Id: Iba40a770a1df2dfff0dd1c874c491dfbe1cceb58
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Orgad Shaneh
2018-06-26 07:58:04 +03:00
committed by Orgad Shaneh
parent caff9f9aac
commit b82ffb917b
5 changed files with 22 additions and 1 deletions

View File

@@ -276,6 +276,7 @@ void ShellCommand::run(QFutureInterface<void> &future)
QString stdOut;
QString stdErr;
emit started();
if (d->m_progressParser)
d->m_progressParser->setFuture(&future);
else

View File

@@ -154,6 +154,7 @@ public:
signals:
void stdOutText(const QString &);
void stdErrText(const QString &);
void started();
void finished(bool ok, int exitCode, const QVariant &cookie);
void success(const QVariant &cookie);

View File

@@ -157,6 +157,7 @@ public:
QFileSystemWatcher *m_fileWatcher = nullptr; // Delayed creation.
QFileSystemWatcher *m_linkWatcher = nullptr; // Delayed creation (only UNIX/if a link is seen).
bool m_postponeAutoReload = false;
bool m_blockActivated = false;
bool m_checkOnFocusChange = false;
QString m_lastVisitedDirectory = QDir::currentPath();
@@ -597,6 +598,13 @@ void DocumentManager::unexpectFileChange(const QString &fileName)
updateExpectedState(filePathKey(fileName, ResolveLinks));
}
void DocumentManager::setAutoReloadPostponed(bool postponed)
{
d->m_postponeAutoReload = postponed;
if (!postponed)
QTimer::singleShot(500, m_instance, &DocumentManager::checkForReload);
}
static bool saveModifiedFilesHelper(const QList<IDocument *> &documents,
const QString &message, bool *cancelled, bool silently,
const QString &alwaysSaveMessage, bool *alwaysSave,
@@ -990,7 +998,7 @@ void DocumentManager::changedFile(const QString &fileName)
void DocumentManager::checkForReload()
{
if (d->m_changedFiles.isEmpty())
if (d->m_postponeAutoReload || d->m_changedFiles.isEmpty())
return;
if (QApplication::applicationState() != Qt::ApplicationActive)
return;

View File

@@ -69,6 +69,8 @@ public:
static void expectFileChange(const QString &fileName);
static void unexpectFileChange(const QString &fileName);
static void setAutoReloadPostponed(bool enabled);
// recent files
static void addToRecentFiles(const QString &fileName, Id editorId = Id());
Q_SLOT void clearRecentFiles();

View File

@@ -27,6 +27,7 @@
#include "vcsbaseplugin.h"
#include "vcsoutputwindow.h"
#include <coreplugin/documentmanager.h>
#include <coreplugin/vcsmanager.h>
#include <utils/synchronousprocess.h>
@@ -56,6 +57,14 @@ VcsCommand::VcsCommand(const QString &workingDirectory,
return proxy;
});
connect(this, &VcsCommand::started, this, [this] {
if (flags() & ExpectRepoChanges)
Core::DocumentManager::setAutoReloadPostponed(true);
});
connect(this, &VcsCommand::finished, this, [this] {
if (flags() & ExpectRepoChanges)
Core::DocumentManager::setAutoReloadPostponed(false);
});
}
const QProcessEnvironment VcsCommand::processEnvironment() const