From 7591b2f56d557536731c07edcd45e24a36253265 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Wed, 5 Oct 2022 12:38:09 +0200 Subject: [PATCH] VcsCommand: Make runCommand() a static method And rename it to runBlocking() in order to conform a bit more to QtcProcess API. In case of blocking run there is no need to instantiate VcsCommand on user side. This nicely draw a line between async usages (i.e. when start() is called and we need an instance) and blocking ones (i.e. when runBlocking() is called). Change-Id: I1ba94ee36c92956d5044236cb9e2dd896bf3cfcf Reviewed-by: hjk Reviewed-by: Orgad Shaneh --- src/plugins/clearcase/clearcaseplugin.cpp | 12 ++++-------- src/plugins/vcsbase/vcsbaseclient.cpp | 7 ++----- src/plugins/vcsbase/vcscommand.cpp | 13 ++++++++++++- src/plugins/vcsbase/vcscommand.h | 6 +++++- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/plugins/clearcase/clearcaseplugin.cpp b/src/plugins/clearcase/clearcaseplugin.cpp index aac5fc457b5..acd54e53690 100644 --- a/src/plugins/clearcase/clearcaseplugin.cpp +++ b/src/plugins/clearcase/clearcaseplugin.cpp @@ -41,7 +41,6 @@ #include #include -#include #include #include #include @@ -258,7 +257,7 @@ private: QString runCleartoolSync(const FilePath &workingDir, const QStringList &arguments) const; CommandResult runCleartool(const FilePath &workingDir, const QStringList &arguments, int timeOutS, unsigned flags = 0, - QTextCodec *outputCodec = nullptr) const; + QTextCodec *codec = nullptr) const; static void sync(QFutureInterface &future, QStringList files); void history(const FilePath &workingDir, @@ -1655,16 +1654,13 @@ CommandResult ClearCasePluginPrivate::runCleartool(const FilePath &workingDir, const QStringList &arguments, int timeOutS, unsigned flags, - QTextCodec *outputCodec) const + QTextCodec *codec) const { if (m_settings.ccBinaryPath.isEmpty()) return CommandResult(ProcessResult::StartFailed, Tr::tr("No ClearCase executable specified.")); - std::unique_ptr command; - command.reset(VcsBaseClient::createVcsCommand(workingDir, Environment::systemEnvironment())); - command->addFlags(flags); - command->setCodec(outputCodec); - return command->runCommand({m_settings.ccBinaryPath, arguments}, timeOutS); + return VcsCommand::runBlocking(workingDir, Environment::systemEnvironment(), + {m_settings.ccBinaryPath, arguments}, flags, timeOutS, codec); } IEditor *ClearCasePluginPrivate::showOutputInEditor(const QString& title, const QString &output, diff --git a/src/plugins/vcsbase/vcsbaseclient.cpp b/src/plugins/vcsbase/vcsbaseclient.cpp index a2ea4b9ef89..6c5354a99ef 100644 --- a/src/plugins/vcsbase/vcsbaseclient.cpp +++ b/src/plugins/vcsbase/vcsbaseclient.cpp @@ -137,11 +137,8 @@ CommandResult VcsBaseClientImpl::vcsSynchronousExec(const FilePath &workingDir, CommandResult VcsBaseClientImpl::vcsSynchronousExec(const FilePath &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()); + return VcsCommand::runBlocking(workingDir, processEnvironment(), cmdLine, flags, + timeoutS > 0 ? timeoutS : vcsTimeoutS(), codec); } void VcsBaseClientImpl::resetCachedVcsInfo(const FilePath &workingDir) diff --git a/src/plugins/vcsbase/vcscommand.cpp b/src/plugins/vcsbase/vcscommand.cpp index 01351f65faf..813bb865ebe 100644 --- a/src/plugins/vcsbase/vcscommand.cpp +++ b/src/plugins/vcsbase/vcscommand.cpp @@ -383,7 +383,18 @@ ProcessResult VcsCommand::result() const return d->m_result; } -CommandResult VcsCommand::runCommand(const CommandLine &command, int timeoutS) +CommandResult VcsCommand::runBlocking(const Utils::FilePath &workingDirectory, + const Utils::Environment &environment, + const Utils::CommandLine &command, unsigned flags, + int timeoutS, QTextCodec *codec) +{ + VcsCommand vcsCommand(workingDirectory, environment); + vcsCommand.addFlags(flags); + vcsCommand.setCodec(codec); + return vcsCommand.runBlockingHelper(command, timeoutS); +} + +CommandResult VcsCommand::runBlockingHelper(const CommandLine &command, int timeoutS) { QtcProcess process; if (command.executable().isEmpty()) diff --git a/src/plugins/vcsbase/vcscommand.h b/src/plugins/vcsbase/vcscommand.h index d4e5697624d..45ebf117628 100644 --- a/src/plugins/vcsbase/vcscommand.h +++ b/src/plugins/vcsbase/vcscommand.h @@ -113,7 +113,10 @@ public: void setProgressParser(ProgressParser *parser); void setProgressiveOutput(bool progressive); - CommandResult runCommand(const Utils::CommandLine &command, int timeoutS = 10); + static CommandResult runBlocking(const Utils::FilePath &workingDirectory, + const Utils::Environment &environmentconst, + const Utils::CommandLine &command, unsigned flags, + int timeoutS, QTextCodec *codec); void cancel(); QString cleanedStdOut() const; @@ -134,6 +137,7 @@ signals: void runCommandFinished(const Utils::FilePath &workingDirectory); private: + CommandResult runBlockingHelper(const Utils::CommandLine &command, int timeoutS); void postRunCommand(const Utils::FilePath &workingDirectory); class Internal::VcsCommandPrivate *const d;