forked from qt-creator/qt-creator
Improve safety of VcsCommand
Amends 6e85ff9f4b
Using "invokeMethod(m_outputWindow, ..." has the disadvantage that it
crashes if m_outputWindow was deleted. This is nicely handled when
connecting to signals, so switch back to signals.
Change-Id: I6a681ac48a86536fa8e69e42d3c61ffa9d30c3d5
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -42,7 +42,6 @@ VcsCommand::VcsCommand(const QString &workingDirectory, const Environment &envir
|
||||
{
|
||||
VcsOutputWindow::setRepository(workingDirectory);
|
||||
setDisableUnixTerminal();
|
||||
m_outputWindow = VcsOutputWindow::instance();
|
||||
m_sshPrompt = VcsBase::sshPrompt();
|
||||
|
||||
connect(this, &VcsCommand::started, this, [this] {
|
||||
@@ -53,6 +52,15 @@ VcsCommand::VcsCommand(const QString &workingDirectory, const Environment &envir
|
||||
if (flags() & ExpectRepoChanges)
|
||||
Utils::GlobalFileChangeBlocker::instance()->forceBlocked(false);
|
||||
});
|
||||
|
||||
VcsOutputWindow *outputWindow = VcsOutputWindow::instance();
|
||||
connect(this, &ShellCommand::append, outputWindow, [outputWindow](const QString &t) {
|
||||
outputWindow->append(t);
|
||||
});
|
||||
connect(this, &ShellCommand::appendSilently, outputWindow, &VcsOutputWindow::appendSilently);
|
||||
connect(this, &ShellCommand::appendError, outputWindow, &VcsOutputWindow::appendError);
|
||||
connect(this, &ShellCommand::appendCommand, outputWindow, &VcsOutputWindow::appendCommand);
|
||||
connect(this, &ShellCommand::appendMessage, outputWindow, &VcsOutputWindow::appendMessage);
|
||||
}
|
||||
|
||||
const Environment VcsCommand::processEnvironment() const
|
||||
@@ -70,41 +78,6 @@ void VcsCommand::runCommand(SynchronousProcess &proc,
|
||||
emitRepositoryChanged(workingDirectory);
|
||||
}
|
||||
|
||||
void VcsCommand::append(const QString &text)
|
||||
{
|
||||
QMetaObject::invokeMethod(m_outputWindow, [this, text] {
|
||||
m_outputWindow->append(text);
|
||||
});
|
||||
}
|
||||
|
||||
void VcsCommand::appendSilently(const QString &text)
|
||||
{
|
||||
QMetaObject::invokeMethod(m_outputWindow, [this, text] {
|
||||
m_outputWindow->appendSilently(text);
|
||||
});
|
||||
}
|
||||
|
||||
void VcsCommand::appendError(const QString &text)
|
||||
{
|
||||
QMetaObject::invokeMethod(m_outputWindow, [this, text] {
|
||||
m_outputWindow->appendError(text);
|
||||
});
|
||||
}
|
||||
|
||||
void VcsCommand::appendCommand(const QString &workingDirectory, const Utils::CommandLine &command)
|
||||
{
|
||||
QMetaObject::invokeMethod(m_outputWindow, [this, workingDirectory, command] {
|
||||
m_outputWindow->appendCommand(workingDirectory, command);
|
||||
});
|
||||
}
|
||||
|
||||
void VcsCommand::appendMessage(const QString &text)
|
||||
{
|
||||
QMetaObject::invokeMethod(m_outputWindow, [this, text] {
|
||||
m_outputWindow->appendMessage(text);
|
||||
});
|
||||
}
|
||||
|
||||
void VcsCommand::emitRepositoryChanged(const QString &workingDirectory)
|
||||
{
|
||||
if (m_preventRepositoryChanged || !(flags() & VcsCommand::ExpectRepoChanges))
|
||||
|
||||
@@ -51,13 +51,6 @@ public:
|
||||
const Utils::CommandLine &command,
|
||||
const QString &workDirectory = {}) override;
|
||||
|
||||
protected:
|
||||
void append(const QString &text) override;
|
||||
void appendSilently(const QString &text) override;
|
||||
void appendError(const QString &text) override;
|
||||
void appendCommand(const QString &workingDirectory, const Utils::CommandLine &command) override;
|
||||
void appendMessage(const QString &text) override;
|
||||
|
||||
private:
|
||||
void emitRepositoryChanged(const QString &workingDirectory);
|
||||
|
||||
@@ -65,7 +58,6 @@ private:
|
||||
|
||||
QString m_sshPrompt;
|
||||
bool m_preventRepositoryChanged;
|
||||
VcsOutputWindow *m_outputWindow = nullptr;
|
||||
};
|
||||
|
||||
} // namespace VcsBase
|
||||
|
||||
Reference in New Issue
Block a user