Vcs: Simplify VcsCommand::runCommand interface

The timeout and exit code interpreter properties are already
accessible via the SynchronousProcess parameter.

Change-Id: I1ba9c768a781009df65b5070a1d017c41d7e2663
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
hjk
2021-05-14 13:28:13 +02:00
parent b2dc771d80
commit 73c0175f4b
9 changed files with 21 additions and 24 deletions

View File

@@ -274,8 +274,9 @@ void ShellCommand::run(QFutureInterface<void> &future)
for (int j = 0; j < count; j++) { for (int j = 0; j < count; j++) {
const Internal::ShellCommandPrivate::Job &job = d->m_jobs.at(j); const Internal::ShellCommandPrivate::Job &job = d->m_jobs.at(j);
SynchronousProcess proc; SynchronousProcess proc;
runCommand(proc, job.command, job.timeoutS, job.workingDirectory, proc.setExitCodeInterpreter(job.exitCodeInterpreter);
job.exitCodeInterpreter); proc.setTimeoutS(job.timeoutS);
runCommand(proc, job.command, job.workingDirectory);
stdOut += proc.stdOut(); stdOut += proc.stdOut();
stdErr += proc.stdErr(); stdErr += proc.stdErr();
d->m_lastExecExitCode = proc.exitCode(); d->m_lastExecExitCode = proc.exitCode();
@@ -307,9 +308,8 @@ void ShellCommand::run(QFutureInterface<void> &future)
} }
void ShellCommand::runCommand(SynchronousProcess &proc, void ShellCommand::runCommand(SynchronousProcess &proc,
const CommandLine &command, int timeoutS, const CommandLine &command,
const QString &workingDirectory, const QString &workingDirectory)
const ExitCodeInterpreter &interpreter)
{ {
const QString dir = workDirectory(workingDirectory); const QString dir = workDirectory(workingDirectory);
@@ -323,9 +323,6 @@ void ShellCommand::runCommand(SynchronousProcess &proc,
if (!(d->m_flags & SuppressCommandLogging)) if (!(d->m_flags & SuppressCommandLogging))
emit proxy->appendCommand(dir, command); emit proxy->appendCommand(dir, command);
proc.setTimeoutS(timeoutS);
proc.setExitCodeInterpreter(interpreter);
if ((d->m_flags & FullySynchronously) if ((d->m_flags & FullySynchronously)
|| (!(d->m_flags & NoFullySync) || (!(d->m_flags & NoFullySync)
&& QThread::currentThread() == QCoreApplication::instance()->thread())) { && QThread::currentThread() == QCoreApplication::instance()->thread())) {

View File

@@ -144,9 +144,7 @@ public:
// be triggered! // be triggered!
virtual void runCommand(Utils::SynchronousProcess &process, virtual void runCommand(Utils::SynchronousProcess &process,
const CommandLine &command, const CommandLine &command,
int timeoutS, const QString &workingDirectory = QString());
const QString &workingDirectory = QString(),
const ExitCodeInterpreter &interpreter = {});
void cancel(); void cancel();

View File

@@ -1668,11 +1668,12 @@ ClearCasePluginPrivate::runCleartool(const QString &workingDir,
} }
SynchronousProcess proc; SynchronousProcess proc;
proc.setTimeoutS(timeOutS);
VcsCommand command(workingDir, Environment::systemEnvironment()); VcsCommand command(workingDir, Environment::systemEnvironment());
command.addFlags(flags); command.addFlags(flags);
command.setCodec(outputCodec); command.setCodec(outputCodec);
command.runCommand(proc, {executable, arguments}, timeOutS); command.runCommand(proc, {executable, arguments});
response.error = proc.result() != QtcProcess::Finished; response.error = proc.result() != QtcProcess::Finished;
if (response.error) if (response.error)

View File

@@ -1447,11 +1447,12 @@ CvsResponse CvsPluginPrivate::runCvs(const QString &workingDirectory,
} }
// Run, connect stderr to the output window // Run, connect stderr to the output window
SynchronousProcess proc; SynchronousProcess proc;
proc.setTimeoutS(timeOutS);
VcsCommand command(workingDirectory, Environment::systemEnvironment()); VcsCommand command(workingDirectory, Environment::systemEnvironment());
command.addFlags(flags); command.addFlags(flags);
command.setCodec(outputCodec); command.setCodec(outputCodec);
command.runCommand(proc, {executable, m_settings.addOptions(arguments)}, timeOutS); command.runCommand(proc, {executable, m_settings.addOptions(arguments)});
response.result = CvsResponse::OtherError; response.result = CvsResponse::OtherError;
response.stdErr = proc.stdErr(); response.stdErr = proc.stdErr();

View File

@@ -195,7 +195,8 @@ public:
watcher.setFuture(m_fi.future()); watcher.setFuture(m_fi.future());
connect(command.data(), &VcsCommand::stdOutText, this, &GitGrepRunner::read); connect(command.data(), &VcsCommand::stdOutText, this, &GitGrepRunner::read);
SynchronousProcess proc; SynchronousProcess proc;
command->runCommand(proc, {GitClient::instance()->vcsBinary(), arguments}, 0); proc.setTimeoutS(0);
command->runCommand(proc, {GitClient::instance()->vcsBinary(), arguments});
switch (proc.result()) { switch (proc.result()) {
case QtcProcess::TerminatedAbnormally: case QtcProcess::TerminatedAbnormally:
case QtcProcess::StartFailed: case QtcProcess::StartFailed:

View File

@@ -179,10 +179,11 @@ bool MercurialClient::synchronousPull(const QString &workingDir, const QString &
Environment env = Environment::systemEnvironment(); Environment env = Environment::systemEnvironment();
env.set("LANGUAGE", "C"); env.set("LANGUAGE", "C");
SynchronousProcess proc; SynchronousProcess proc;
proc.setTimeoutS(vcsTimeoutS());
VcsCommand command(workingDir, env); VcsCommand command(workingDir, env);
command.addFlags(flags); command.addFlags(flags);
command.runCommand(proc, {vcsBinary(), args}, vcsTimeoutS()); command.runCommand(proc, {vcsBinary(), args});
const bool ok = proc.result() == QtcProcess::Finished; const bool ok = proc.result() == QtcProcess::Finished;

View File

@@ -162,7 +162,8 @@ void VcsBaseClientImpl::vcsFullySynchronousExec(SynchronousProcess &proc,
command.addFlags(flags); command.addFlags(flags);
if (codec) if (codec)
command.setCodec(codec); command.setCodec(codec);
command.runCommand(proc, cmdLine, (timeoutS > 0) ? timeoutS : vcsTimeoutS()); proc.setTimeoutS(timeoutS > 0 ? timeoutS : vcsTimeoutS());
command.runCommand(proc, cmdLine);
} }
void VcsBaseClientImpl::resetCachedVcsInfo(const QString &workingDir) void VcsBaseClientImpl::resetCachedVcsInfo(const QString &workingDir)
@@ -211,9 +212,10 @@ void VcsBaseClientImpl::vcsSynchronousExec(SynchronousProcess &proc, const QStri
{ {
Environment env = processEnvironment(); Environment env = processEnvironment();
VcsCommand command(workingDir, env.size() == 0 ? Environment::systemEnvironment() : env); VcsCommand command(workingDir, env.size() == 0 ? Environment::systemEnvironment() : env);
proc.setTimeoutS(vcsTimeoutS());
command.addFlags(flags); command.addFlags(flags);
command.setCodec(outputCodec); command.setCodec(outputCodec);
command.runCommand(proc, {vcsBinary(), args}, vcsTimeoutS()); command.runCommand(proc, {vcsBinary(), args});
} }
int VcsBaseClientImpl::vcsTimeoutS() const int VcsBaseClientImpl::vcsTimeoutS() const

View File

@@ -78,11 +78,9 @@ const Environment VcsCommand::processEnvironment() const
void VcsCommand::runCommand(SynchronousProcess &proc, void VcsCommand::runCommand(SynchronousProcess &proc,
const CommandLine &command, const CommandLine &command,
int timeoutS, const QString &workingDirectory)
const QString &workingDirectory,
const ExitCodeInterpreter &interpreter)
{ {
ShellCommand::runCommand(proc, command, timeoutS, workingDirectory, interpreter); ShellCommand::runCommand(proc, command, workingDirectory);
emitRepositoryChanged(workingDirectory); emitRepositoryChanged(workingDirectory);
} }

View File

@@ -47,9 +47,7 @@ public:
void runCommand(Utils::SynchronousProcess &process, void runCommand(Utils::SynchronousProcess &process,
const Utils::CommandLine &command, const Utils::CommandLine &command,
int timeoutS, const QString &workDirectory = {}) override;
const QString &workDirectory = QString(),
const Utils::ExitCodeInterpreter &interpreter = {}) override;
private: private:
void emitRepositoryChanged(const QString &workingDirectory); void emitRepositoryChanged(const QString &workingDirectory);