Utils: Make process results accessible through QtcProcess object

The result is fully stored in the object anyway. Using the extra
SynchronousProcessResponse structure only causes copies of
the data and complicates access on the user side in
a lot of cases.

The result bits are now also accessible individually.

There's obvious room for follow-up changes on the topic, e.g.
ShellCommand::runCommand's parameter list could shrink to
just a SynchronousProcess parameter.

Change-Id: I45aa7eb23832340be06905929280c012e1217263
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
hjk
2021-05-12 14:25:50 +02:00
parent f23b27ded6
commit 55f768e1b0
54 changed files with 747 additions and 706 deletions

View File

@@ -154,15 +154,15 @@ QString VcsBaseClientImpl::stripLastNewline(const QString &in)
return in;
}
SynchronousProcessResponse
VcsBaseClientImpl::vcsFullySynchronousExec(const QString &workingDir, const CommandLine &cmdLine,
unsigned flags, int timeoutS, QTextCodec *codec) const
void VcsBaseClientImpl::vcsFullySynchronousExec(SynchronousProcess &proc,
const QString &workingDir, const CommandLine &cmdLine,
unsigned flags, int timeoutS, QTextCodec *codec) const
{
VcsCommand command(workingDir, processEnvironment());
command.addFlags(flags);
if (codec)
command.setCodec(codec);
return command.runCommand(cmdLine, (timeoutS > 0) ? timeoutS : vcsTimeoutS());
command.runCommand(proc, cmdLine, (timeoutS > 0) ? timeoutS : vcsTimeoutS());
}
void VcsBaseClientImpl::resetCachedVcsInfo(const QString &workingDir)
@@ -183,11 +183,11 @@ void VcsBaseClientImpl::annotateRevisionRequested(const QString &workingDirector
annotate(workingDirectory, file, changeCopy, line);
}
SynchronousProcessResponse
VcsBaseClientImpl::vcsFullySynchronousExec(const QString &workingDir, const QStringList &args,
unsigned flags, int timeoutS, QTextCodec *codec) const
void VcsBaseClientImpl::vcsFullySynchronousExec(SynchronousProcess &proc,
const QString &workingDir, const QStringList &args,
unsigned flags, int timeoutS, QTextCodec *codec) const
{
return vcsFullySynchronousExec(workingDir, {vcsBinary(), args}, flags, timeoutS, codec);
vcsFullySynchronousExec(proc, workingDir, {vcsBinary(), args}, flags, timeoutS, codec);
}
VcsCommand *VcsBaseClientImpl::vcsExec(const QString &workingDirectory, const QStringList &arguments,
@@ -204,13 +204,16 @@ VcsCommand *VcsBaseClientImpl::vcsExec(const QString &workingDirectory, const QS
return command;
}
SynchronousProcessResponse VcsBaseClientImpl::vcsSynchronousExec(const QString &workingDir,
const QStringList &args,
unsigned flags,
QTextCodec *outputCodec) const
void VcsBaseClientImpl::vcsSynchronousExec(SynchronousProcess &proc, const QString &workingDir,
const QStringList &args,
unsigned flags,
QTextCodec *outputCodec) const
{
return VcsBase::runVcs(workingDir, {vcsBinary(), args}, vcsTimeoutS(), flags,
outputCodec, processEnvironment());
Environment env = processEnvironment();
VcsCommand command(workingDir, env.size() == 0 ? Environment::systemEnvironment() : env);
command.addFlags(flags);
command.setCodec(outputCodec);
command.runCommand(proc, {vcsBinary(), args}, vcsTimeoutS());
}
int VcsBaseClientImpl::vcsTimeoutS() const
@@ -264,10 +267,11 @@ bool VcsBaseClient::synchronousCreateRepository(const QString &workingDirectory,
{
QStringList args(vcsCommandString(CreateRepositoryCommand));
args << extraOptions;
SynchronousProcessResponse result = vcsFullySynchronousExec(workingDirectory, args);
if (result.result != SynchronousProcessResponse::Finished)
SynchronousProcess proc;
vcsFullySynchronousExec(proc, workingDirectory, args);
if (proc.result() != QtcProcess::Finished)
return false;
VcsOutputWindow::append(result.stdOut());
VcsOutputWindow::append(proc.stdOut());
resetCachedVcsInfo(workingDirectory);
@@ -283,9 +287,10 @@ bool VcsBaseClient::synchronousClone(const QString &workingDir,
args << vcsCommandString(CloneCommand)
<< extraOptions << srcLocation << dstLocation;
SynchronousProcessResponse result = vcsFullySynchronousExec(workingDir, args);
SynchronousProcess proc;
vcsFullySynchronousExec(proc, workingDir, args);
resetCachedVcsInfo(workingDir);
return result.result == SynchronousProcessResponse::Finished;
return proc.result() == QtcProcess::Finished;
}
bool VcsBaseClient::synchronousAdd(const QString &workingDir, const QString &filename,
@@ -293,7 +298,9 @@ bool VcsBaseClient::synchronousAdd(const QString &workingDir, const QString &fil
{
QStringList args;
args << vcsCommandString(AddCommand) << extraOptions << filename;
return vcsFullySynchronousExec(workingDir, args).result == SynchronousProcessResponse::Finished;
SynchronousProcess proc;
vcsFullySynchronousExec(proc, workingDir, args);
return proc.result() == QtcProcess::Finished;
}
bool VcsBaseClient::synchronousRemove(const QString &workingDir, const QString &filename,
@@ -301,7 +308,9 @@ bool VcsBaseClient::synchronousRemove(const QString &workingDir, const QString &
{
QStringList args;
args << vcsCommandString(RemoveCommand) << extraOptions << filename;
return vcsFullySynchronousExec(workingDir, args).result == SynchronousProcessResponse::Finished;
SynchronousProcess proc;
vcsFullySynchronousExec(proc, workingDir, args);
return proc.result() == QtcProcess::Finished;
}
bool VcsBaseClient::synchronousMove(const QString &workingDir,
@@ -310,7 +319,9 @@ bool VcsBaseClient::synchronousMove(const QString &workingDir,
{
QStringList args;
args << vcsCommandString(MoveCommand) << extraOptions << from << to;
return vcsFullySynchronousExec(workingDir, args).result == SynchronousProcessResponse::Finished;
SynchronousProcess proc;
vcsFullySynchronousExec(proc, workingDir, args);
return proc.result() == QtcProcess::Finished;
}
bool VcsBaseClient::synchronousPull(const QString &workingDir,
@@ -324,8 +335,9 @@ bool VcsBaseClient::synchronousPull(const QString &workingDir,
VcsCommand::SshPasswordPrompt
| VcsCommand::ShowStdOut
| VcsCommand::ShowSuccessMessage;
const SynchronousProcessResponse resp = vcsSynchronousExec(workingDir, args, flags);
const bool ok = resp.result == SynchronousProcessResponse::Finished;
SynchronousProcess proc;
vcsSynchronousExec(proc, workingDir, args, flags);
const bool ok = proc.result() == QtcProcess::Finished;
if (ok)
emit changed(QVariant(workingDir));
return ok;
@@ -342,8 +354,9 @@ bool VcsBaseClient::synchronousPush(const QString &workingDir,
VcsCommand::SshPasswordPrompt
| VcsCommand::ShowStdOut
| VcsCommand::ShowSuccessMessage;
const SynchronousProcessResponse resp = vcsSynchronousExec(workingDir, args, flags);
return resp.result == SynchronousProcessResponse::Finished;
SynchronousProcess proc;
vcsSynchronousExec(proc, workingDir, args, flags);
return proc.result() == QtcProcess::Finished;
}
VcsBaseEditorWidget *VcsBaseClient::annotate(

View File

@@ -99,12 +99,12 @@ public:
static QString stripLastNewline(const QString &in);
// Fully synchronous VCS execution (QProcess-based)
Utils::SynchronousProcessResponse
vcsFullySynchronousExec(const QString &workingDir, const QStringList &args,
unsigned flags = 0, int timeoutS = -1, QTextCodec *codec = nullptr) const;
Utils::SynchronousProcessResponse
vcsFullySynchronousExec(const QString &workingDir, const Utils::CommandLine &cmdLine,
unsigned flags = 0, int timeoutS = -1, QTextCodec *codec = nullptr) const;
void vcsFullySynchronousExec(Utils::SynchronousProcess &process,
const QString &workingDir, const QStringList &args,
unsigned flags = 0, int timeoutS = -1, QTextCodec *codec = nullptr) const;
void vcsFullySynchronousExec(Utils::SynchronousProcess &process,
const QString &workingDir, const Utils::CommandLine &cmdLine,
unsigned flags = 0, int timeoutS = -1, QTextCodec *codec = nullptr) const;
// Simple helper to execute a single command using createCommand and enqueueJob.
@@ -119,10 +119,11 @@ protected:
// Synchronous VCS execution using Utils::SynchronousProcess, with
// log windows updating (using VcsBasePlugin::runVcs with flags)
Utils::SynchronousProcessResponse vcsSynchronousExec(const QString &workingDir,
const QStringList &args,
unsigned flags = 0,
QTextCodec *outputCodec = nullptr) const;
void vcsSynchronousExec(Utils::SynchronousProcess &proc,
const QString &workingDir,
const QStringList &args,
unsigned flags = 0,
QTextCodec *outputCodec = nullptr) const;
private:
void saveSettings();

View File

@@ -752,21 +752,6 @@ void setProcessEnvironment(Environment *e, bool forceCLocale, const QString &ssh
e->set("SSH_ASKPASS", sshPromptBinary);
}
// Run a process synchronously, returning Utils::SynchronousProcessResponse
// response struct and using the VcsBasePlugin flags as applicable
SynchronousProcessResponse runVcs(const QString &workingDir,
const CommandLine &cmd,
int timeOutS,
unsigned flags,
QTextCodec *outputCodec,
const Environment &env)
{
VcsCommand command(workingDir, env.size() == 0 ? Environment::systemEnvironment() : env);
command.addFlags(flags);
command.setCodec(outputCodec);
return command.runCommand(cmd, timeOutS);
}
} // namespace VcsBase
#include "vcsbaseplugin.moc"

View File

@@ -147,13 +147,6 @@ VCSBASE_EXPORT void setSource(Core::IDocument *document, const QString &source);
// Returns the source of editor contents.
VCSBASE_EXPORT QString source(Core::IDocument *document);
VCSBASE_EXPORT Utils::SynchronousProcessResponse runVcs(const QString &workingDir,
const Utils::CommandLine &cmd,
int timeOutS,
unsigned flags = 0,
QTextCodec *outputCodec = nullptr,
const Utils::Environment &env = {});
class VCSBASE_EXPORT VcsBasePluginPrivate : public Core::IVersionControl
{
Q_OBJECT

View File

@@ -76,14 +76,14 @@ const Environment VcsCommand::processEnvironment() const
return env;
}
SynchronousProcessResponse VcsCommand::runCommand(const CommandLine &command, int timeoutS,
const QString &workingDirectory,
const ExitCodeInterpreter &interpreter)
void VcsCommand::runCommand(SynchronousProcess &proc,
const CommandLine &command,
int timeoutS,
const QString &workingDirectory,
const ExitCodeInterpreter &interpreter)
{
SynchronousProcessResponse response
= Core::ShellCommand::runCommand(command, timeoutS, workingDirectory, interpreter);
ShellCommand::runCommand(proc, command, timeoutS, workingDirectory, interpreter);
emitRepositoryChanged(workingDirectory);
return response;
}
void VcsCommand::emitRepositoryChanged(const QString &workingDirectory)

View File

@@ -45,10 +45,11 @@ public:
const Utils::Environment processEnvironment() const override;
Utils::SynchronousProcessResponse runCommand(const Utils::CommandLine &command,
int timeoutS,
const QString &workDirectory = QString(),
const Utils::ExitCodeInterpreter &interpreter = {}) override;
void runCommand(Utils::SynchronousProcess &process,
const Utils::CommandLine &command,
int timeoutS,
const QString &workDirectory = QString(),
const Utils::ExitCodeInterpreter &interpreter = {}) override;
private:
void emitRepositoryChanged(const QString &workingDirectory);