ShellCommand: De-virtualize environment()

Provide instead a protected setter, used in VcsCommand c'tor.

Remove a forceCLocale arg from setProcessEnvironment() method,
as it is used only in VcsCommand context when
ShellCommand::ForceCLocale flag was set. Move setting
C locale env directly to the shell command, just before
the command is executed, so that we are sure the flag
was already set.

Modify env directly in VcsCommand c'tor with regards to
SSH_ASKPASS variable.

Change-Id: Icff555ade4984368f7ce79f762d1bb5d3614076a
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Jarek Kobus
2022-07-13 17:54:59 +02:00
parent 68bb3b99a9
commit 85071d8e8d
7 changed files with 22 additions and 23 deletions

View File

@@ -79,9 +79,19 @@ public:
~ShellCommandPrivate() { delete m_progressParser; }
Environment environment()
{
if (!(m_flags & ShellCommand::ForceCLocale))
return m_environment;
m_environment.set("LANG", "C");
m_environment.set("LANGUAGE", "C");
return m_environment;
}
QString m_displayName;
const FilePath m_defaultWorkingDirectory;
const Environment m_environment;
Environment m_environment;
QVariant m_cookie;
QTextCodec *m_codec = nullptr;
ProgressParser *m_progressParser = nullptr;
@@ -152,9 +162,9 @@ const FilePath &ShellCommand::defaultWorkingDirectory() const
return d->m_defaultWorkingDirectory;
}
Environment ShellCommand::environment() const
void ShellCommand::setEnvironment(const Environment &env)
{
return d->m_environment;
d->m_environment = env;
}
int ShellCommand::defaultTimeoutS() const
@@ -310,7 +320,7 @@ void ShellCommand::runCommand(QtcProcess &proc,
proc.setCommand(command);
if (d->m_disableUnixTerminal)
proc.setDisableUnixTerminal();
proc.setEnvironment(environment());
proc.setEnvironment(d->environment());
if (d->m_flags & MergeOutputChannels)
proc.setProcessChannelMode(QProcess::MergedChannels);
if (d->m_codec)

View File

@@ -149,7 +149,7 @@ signals:
void appendMessage(const QString &text);
protected:
virtual Environment environment() const;
void setEnvironment(const Environment &env);
void setDisableUnixTerminal();
int timeoutS() const;

View File

@@ -134,7 +134,7 @@ void VcsBaseClientImpl::enqueueJob(ShellCommand *cmd, const QStringList &args,
Environment VcsBaseClientImpl::processEnvironment() const
{
Environment environment = Environment::systemEnvironment();
VcsBase::setProcessEnvironment(&environment, false);
VcsBase::setProcessEnvironment(&environment);
return environment;
}

View File

@@ -734,12 +734,8 @@ QString source(IDocument *document)
return document->property(SOURCE_PROPERTY).toString();
}
void setProcessEnvironment(Environment *e, bool forceCLocale)
void setProcessEnvironment(Environment *e)
{
if (forceCLocale) {
e->set("LANG", "C");
e->set("LANGUAGE", "C");
}
const QString prompt = Internal::VcsPlugin::instance()->settings().sshPasswordPrompt.value();
if (!prompt.isEmpty())
e->set("SSH_ASKPASS", prompt);

View File

@@ -130,8 +130,7 @@ VCSBASE_EXPORT Utils::FilePath findRepositoryForFile(const Utils::FilePath &file
// 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(Utils::Environment *e,
bool forceCLocale);
VCSBASE_EXPORT void setProcessEnvironment(Utils::Environment *e);
// Sets the source of editor contents, can be directory or file.
VCSBASE_EXPORT void setSource(Core::IDocument *document, const QString &source);
// Returns the source of editor contents.

View File

@@ -48,6 +48,10 @@ VcsCommand::VcsCommand(const FilePath &workingDirectory, const Environment &envi
ShellCommand(workingDirectory, environment),
m_preventRepositoryChanged(false)
{
Environment env = environment;
VcsBase::setProcessEnvironment(&env);
setEnvironment(env);
connect(ICore::instance(), &ICore::coreAboutToClose, this, [this] {
m_preventRepositoryChanged = true;
abort();
@@ -75,13 +79,6 @@ VcsCommand::VcsCommand(const FilePath &workingDirectory, const Environment &envi
connect(this, &ShellCommand::appendMessage, outputWindow, &VcsOutputWindow::appendMessage);
}
Environment VcsCommand::environment() const
{
Environment env = ShellCommand::environment();
VcsBase::setProcessEnvironment(&env, flags() & ForceCLocale);
return env;
}
void VcsCommand::addTask(QFuture<void> &future)
{
const QString name = displayName();

View File

@@ -36,9 +36,6 @@ class VcsCommand : public Utils::ShellCommand
{
Q_OBJECT
protected:
Utils::Environment environment() const override;
private:
VcsCommand(const Utils::FilePath &defaultWorkingDirectory,
const Utils::Environment &environment);