Vcs/Utils: Use Utils::Environment for ShellCommand

Change-Id: Ica289ab2f83d52270923c4ff4983860cfbe0b494
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2021-05-04 05:54:54 +02:00
parent f5aa7bd9a1
commit 793d673f39
22 changed files with 72 additions and 82 deletions

View File

@@ -119,9 +119,9 @@ void VcsBaseClientImpl::enqueueJob(VcsCommand *cmd, const QStringList &args,
cmd->execute();
}
QProcessEnvironment VcsBaseClientImpl::processEnvironment() const
Environment VcsBaseClientImpl::processEnvironment() const
{
QProcessEnvironment environment = QProcessEnvironment::systemEnvironment();
Environment environment = Environment::systemEnvironment();
VcsBase::setProcessEnvironment(&environment, false);
return environment;
}

View File

@@ -84,7 +84,7 @@ public:
const QString &workingDirectory = QString(),
const Utils::ExitCodeInterpreter &interpreter = Utils::defaultExitCodeInterpreter) const;
virtual QProcessEnvironment processEnvironment() const;
virtual Utils::Environment processEnvironment() const;
// VCS functionality:
virtual VcsBaseEditorWidget *annotate(

View File

@@ -30,6 +30,8 @@
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/progressmanager/progressmanager.h>
#include <diffeditor/diffutils.h>
#include <utils/environment.h>
#include <utils/qtcassert.h>
#include <utils/runextensions.h>
@@ -37,6 +39,7 @@
using namespace DiffEditor;
using namespace Core;
using namespace Utils;
namespace VcsBase {
@@ -93,7 +96,7 @@ public:
VcsBaseDiffEditorController *q;
QString m_directory;
QProcessEnvironment m_processEnvironment;
Environment m_processEnvironment;
Utils::FilePath m_vcsBinary;
int m_vscTimeoutS;
QString m_startupFile;
@@ -294,7 +297,7 @@ void VcsBaseDiffEditorController::setVcsBinary(const Utils::FilePath &path)
d->m_vcsBinary = path;
}
void VcsBaseDiffEditorController::setProcessEnvironment(const QProcessEnvironment &value)
void VcsBaseDiffEditorController::setProcessEnvironment(const Environment &value)
{
d->m_processEnvironment = value;
}

View File

@@ -29,14 +29,16 @@
#include <diffeditor/diffeditorcontroller.h>
#include <QProcessEnvironment>
QT_BEGIN_NAMESPACE
class QTextCodec;
QT_END_NAMESPACE
namespace Core { class IDocument; }
namespace Utils { class FilePath; }
namespace Utils {
class Environment;
class FilePath;
} // Utils
namespace VcsBase {
@@ -50,7 +52,7 @@ public:
explicit VcsBaseDiffEditorController(Core::IDocument *document);
~VcsBaseDiffEditorController() override;
void setProcessEnvironment(const QProcessEnvironment &value);
void setProcessEnvironment(const Utils::Environment &value);
void setVcsBinary(const Utils::FilePath &path);
void setVcsTimeoutS(int value);
void setWorkingDirectory(const QString &workingDir);

View File

@@ -742,16 +742,14 @@ QString source(IDocument *document)
return document->property(SOURCE_PROPERTY).toString();
}
void setProcessEnvironment(QProcessEnvironment *e,
bool forceCLocale,
const QString &sshPromptBinary)
void setProcessEnvironment(Environment *e, bool forceCLocale, const QString &sshPromptBinary)
{
if (forceCLocale) {
e->insert("LANG", "C");
e->insert("LANGUAGE", "C");
e->set("LANG", "C");
e->set("LANGUAGE", "C");
}
if (!sshPromptBinary.isEmpty())
e->insert("SSH_ASKPASS", sshPromptBinary);
e->set("SSH_ASKPASS", sshPromptBinary);
}
// Run a process synchronously, returning Utils::SynchronousProcessResponse
@@ -761,9 +759,9 @@ SynchronousProcessResponse runVcs(const QString &workingDir,
int timeOutS,
unsigned flags,
QTextCodec *outputCodec,
const QProcessEnvironment &env)
const Environment &env)
{
VcsCommand command(workingDir, env.isEmpty() ? QProcessEnvironment::systemEnvironment() : env);
VcsCommand command(workingDir, env.size() == 0 ? Environment::systemEnvironment() : env);
command.addFlags(flags);
command.setCodec(outputCodec);
return command.runCommand(cmd, timeOutS);

View File

@@ -30,10 +30,11 @@
#include <coreplugin/icontext.h>
#include <coreplugin/iversioncontrol.h>
#include <coreplugin/vcsmanager.h>
#include <extensionsystem/iplugin.h>
#include <QList>
#include <QProcessEnvironment>
#include <utils/environment.h>
#include <QSharedDataPointer>
QT_BEGIN_NAMESPACE
@@ -138,7 +139,7 @@ VCSBASE_EXPORT bool isSshPromptConfigured();
// Sets up SSH graphical password prompting (note that the latter
// requires a terminal-less process) and sets LANG to 'C' to force English
// (suppress LOCALE warnings/parse commands output) if desired.
VCSBASE_EXPORT void setProcessEnvironment(QProcessEnvironment *e,
VCSBASE_EXPORT void setProcessEnvironment(Utils::Environment *e,
bool forceCLocale,
const QString &sshPasswordPrompt = sshPrompt());
// Sets the source of editor contents, can be directory or file.
@@ -151,7 +152,7 @@ VCSBASE_EXPORT Utils::SynchronousProcessResponse runVcs(const QString &workingDi
int timeOutS,
unsigned flags = 0,
QTextCodec *outputCodec = nullptr,
const QProcessEnvironment &env = {});
const Utils::Environment &env = {});
class VCSBASE_EXPORT VcsBasePluginPrivate : public Core::IVersionControl
{

View File

@@ -30,16 +30,13 @@
#include <coreplugin/documentmanager.h>
#include <coreplugin/vcsmanager.h>
#include <utils/globalfilechangeblocker.h>
#include <utils/synchronousprocess.h>
#include <QProcessEnvironment>
#include <utils/qtcprocess.h>
using namespace Utils;
namespace VcsBase {
VcsCommand::VcsCommand(const QString &workingDirectory,
const QProcessEnvironment &environment) :
VcsCommand::VcsCommand(const QString &workingDirectory, const Environment &environment) :
Core::ShellCommand(workingDirectory, environment),
m_preventRepositoryChanged(false)
{
@@ -71,9 +68,9 @@ VcsCommand::VcsCommand(const QString &workingDirectory,
});
}
const QProcessEnvironment VcsCommand::processEnvironment() const
const Environment VcsCommand::processEnvironment() const
{
QProcessEnvironment env = Core::ShellCommand::processEnvironment();
Environment env = Core::ShellCommand::processEnvironment();
VcsBase::setProcessEnvironment(&env, flags() & ForceCLocale, VcsBase::sshPrompt());
return env;
}

View File

@@ -41,9 +41,9 @@ public:
ExpectRepoChanges = 0x2000, // Expect changes in repository by the command
};
VcsCommand(const QString &defaultWorkingDirectory, const QProcessEnvironment &environment);
VcsCommand(const QString &defaultWorkingDirectory, const Utils::Environment &environment);
const QProcessEnvironment processEnvironment() const override;
const Utils::Environment processEnvironment() const override;
Utils::SynchronousProcessResponse runCommand(const Utils::CommandLine &command,
int timeoutS,