VcsBase: Fix a crash on shutdown

Since GitClient is a static object, it's being deleted after
the git plugin is unloaded. We can't make it a parent of VcsCommand
instances, as the process reaper may be already gone.

Use ExtensionSystem::shutdownGuard() as a parent for VcsCommand
instances instead.

This commit reverts d5e8f70192.

Amends d5e8f70192

Fixes: QTCREATORBUG-31549
Change-Id: I27e6abbfcac2746e8fa4c447010aab43c11444a9
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: André Hartmann <aha_1980@gmx.de>
This commit is contained in:
Jarek Kobus
2024-09-11 18:45:53 +02:00
parent a640b17824
commit 438b774a1a
8 changed files with 10 additions and 19 deletions

View File

@@ -949,7 +949,7 @@ VcsCommand *BazaarPluginPrivate::createInitialCheckoutCommand(const QString &url
{ {
Environment env = m_client.processEnvironment(baseDirectory); Environment env = m_client.processEnvironment(baseDirectory);
env.set("BZR_PROGRESS_BAR", "text"); env.set("BZR_PROGRESS_BAR", "text");
auto command = VcsBaseClient::createVcsCommand(this, baseDirectory, env); auto command = VcsBaseClient::createVcsCommand(baseDirectory, env);
command->addJob({m_client.vcsBinary(baseDirectory), command->addJob({m_client.vcsBinary(baseDirectory),
{m_client.vcsCommandString(BazaarClient::CloneCommand), extraArgs, url, localName}}, -1); {m_client.vcsCommandString(BazaarClient::CloneCommand), extraArgs, url, localName}}, -1);
return command; return command;

View File

@@ -413,8 +413,7 @@ VcsCommand *CvsPluginPrivate::createInitialCheckoutCommand(const QString &url,
QStringList args; QStringList args;
args << QLatin1String("checkout") << url << extraArgs; args << QLatin1String("checkout") << url << extraArgs;
auto command = VcsBaseClient::createVcsCommand(this, baseDirectory, auto command = VcsBaseClient::createVcsCommand(baseDirectory, Environment::systemEnvironment());
Environment::systemEnvironment());
command->setDisplayName(Tr::tr("CVS Checkout")); command->setDisplayName(Tr::tr("CVS Checkout"));
command->addJob({settings().binaryPath(), settings().addOptions(args)}, -1); command->addJob({settings().binaryPath(), settings().addOptions(args)}, -1);
return command; return command;

View File

@@ -931,7 +931,7 @@ VcsCommand *FossilPluginPrivate::createInitialCheckoutCommand(const QString &sou
checkoutPath.createDir(); checkoutPath.createDir();
// Setup the wizard page command job // Setup the wizard page command job
auto command = VcsBaseClient::createVcsCommand(this, checkoutPath, auto command = VcsBaseClient::createVcsCommand(checkoutPath,
fossilClient().processEnvironment(checkoutPath)); fossilClient().processEnvironment(checkoutPath));
if (!isLocalRepository if (!isLocalRepository

View File

@@ -1838,7 +1838,7 @@ VcsCommand *GitPluginPrivate::createInitialCheckoutCommand(const QString &url,
const QString &localName, const QString &localName,
const QStringList &extraArgs) const QStringList &extraArgs)
{ {
auto command = VcsBaseClient::createVcsCommand(this, baseDirectory, auto command = VcsBaseClient::createVcsCommand(baseDirectory,
gitClient().processEnvironment(baseDirectory)); gitClient().processEnvironment(baseDirectory));
command->addFlags(RunFlags::SuppressStdErr); command->addFlags(RunFlags::SuppressStdErr);
command->addJob({gitClient().vcsBinary(baseDirectory), command->addJob({gitClient().vcsBinary(baseDirectory),

View File

@@ -733,7 +733,7 @@ VcsCommand *MercurialPluginPrivate::createInitialCheckoutCommand(const QString &
const QString &localName, const QString &localName,
const QStringList &extraArgs) const QStringList &extraArgs)
{ {
auto command = VcsBaseClient::createVcsCommand(this, baseDirectory, auto command = VcsBaseClient::createVcsCommand(baseDirectory,
mercurialClient().processEnvironment(baseDirectory)); mercurialClient().processEnvironment(baseDirectory));
command->addJob({settings().binaryPath(), {"clone", extraArgs, url, localName}}, -1); command->addJob({settings().binaryPath(), {"clone", extraArgs, url, localName}}, -1);
return command; return command;

View File

@@ -1149,7 +1149,7 @@ VcsCommand *SubversionPluginPrivate::createInitialCheckoutCommand(const QString
args << SubversionClient::AddAuthOptions(); args << SubversionClient::AddAuthOptions();
args << Subversion::Constants::NON_INTERACTIVE_OPTION << extraArgs << url << localName; args << Subversion::Constants::NON_INTERACTIVE_OPTION << extraArgs << url << localName;
auto command = VcsBaseClient::createVcsCommand(this, baseDirectory, auto command = VcsBaseClient::createVcsCommand(baseDirectory,
subversionClient().processEnvironment(baseDirectory)); subversionClient().processEnvironment(baseDirectory));
command->addJob(args, -1); command->addJob(args, -1);
return command; return command;

View File

@@ -16,6 +16,8 @@
#include <coreplugin/editormanager/editormanager.h> #include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/idocument.h> #include <coreplugin/idocument.h>
#include <extensionsystem/shutdownguard.h>
#include <texteditor/textdocument.h> #include <texteditor/textdocument.h>
#include <utils/commandline.h> #include <utils/commandline.h>
@@ -71,8 +73,7 @@ FilePath VcsBaseClientImpl::vcsBinary(const Utils::FilePath &forDirectory) const
VcsCommand *VcsBaseClientImpl::createCommand(const FilePath &workingDirectory, VcsCommand *VcsBaseClientImpl::createCommand(const FilePath &workingDirectory,
VcsBaseEditorWidget *editor) const VcsBaseEditorWidget *editor) const
{ {
auto cmd = createVcsCommand(const_cast<VcsBaseClientImpl *>(this), auto cmd = createVcsCommand(workingDirectory, processEnvironment(workingDirectory));
workingDirectory, processEnvironment(workingDirectory));
if (editor) { if (editor) {
editor->setCommand(cmd); editor->setCommand(cmd);
connect(cmd, &VcsCommand::done, editor, [editor, cmd] { connect(cmd, &VcsCommand::done, editor, [editor, cmd] {
@@ -210,15 +211,9 @@ int VcsBaseClientImpl::vcsTimeoutS() const
VcsCommand *VcsBaseClientImpl::createVcsCommand(const FilePath &defaultWorkingDir, VcsCommand *VcsBaseClientImpl::createVcsCommand(const FilePath &defaultWorkingDir,
const Environment &environment) const Environment &environment)
{
return new VcsCommand(defaultWorkingDir, environment);
}
VcsCommand *VcsBaseClientImpl::createVcsCommand(QObject *parent, const FilePath &defaultWorkingDir,
const Environment &environment)
{ {
auto command = new VcsCommand(defaultWorkingDir, environment); auto command = new VcsCommand(defaultWorkingDir, environment);
command->setParent(parent); command->setParent(ExtensionSystem::shutdownGuard());
return command; return command;
} }

View File

@@ -42,11 +42,8 @@ public:
virtual Utils::FilePath vcsBinary(const Utils::FilePath &forDirectory) const; virtual Utils::FilePath vcsBinary(const Utils::FilePath &forDirectory) const;
int vcsTimeoutS() const; int vcsTimeoutS() const;
// TODO: For master: remove this overload.
static VcsCommand *createVcsCommand(const Utils::FilePath &defaultWorkingDir, static VcsCommand *createVcsCommand(const Utils::FilePath &defaultWorkingDir,
const Utils::Environment &environment); const Utils::Environment &environment);
static VcsCommand *createVcsCommand(QObject *parent, const Utils::FilePath &defaultWorkingDir,
const Utils::Environment &environment);
VcsBaseEditorWidget *createVcsEditor(Utils::Id kind, QString title, VcsBaseEditorWidget *createVcsEditor(Utils::Id kind, QString title,
const Utils::FilePath &source, QTextCodec *codec, const Utils::FilePath &source, QTextCodec *codec,