From b04b24ca8194f890d4cc8952b670d68a37447f8e Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Mon, 5 Sep 2022 18:04:54 +0200 Subject: [PATCH] GitGrep: Use QtcProcess instead of VcsCommand Originally VcsCommand was created in main thread, while VcsCommand::runCommand() has been called in worker thread. Fix it by using QtcProcess directly in worker thread. Change-Id: I65f3476c0b89466c4347b0469e4cbad89c09072d Reviewed-by: Orgad Shaneh --- src/plugins/git/gitgrep.cpp | 40 ++++++++++++++----------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/src/plugins/git/gitgrep.cpp b/src/plugins/git/gitgrep.cpp index 5acabdfd597..f5101d5699e 100644 --- a/src/plugins/git/gitgrep.cpp +++ b/src/plugins/git/gitgrep.cpp @@ -4,30 +4,24 @@ #include "gitgrep.h" #include "gitclient.h" -#include -#include #include #include #include -#include #include -#include +#include #include #include -#include #include +#include #include -#include #include #include -#include #include #include -#include #include #include @@ -59,8 +53,8 @@ public: : m_parameters(parameters) { m_directory = FilePath::fromString(parameters.additionalParameters.toString()); - m_command.reset(GitClient::instance()->createCommand(m_directory)); m_vcsBinary = GitClient::instance()->vcsBinary(); + m_environment = GitClient::instance()->processEnvironment(); } struct Match @@ -130,13 +124,12 @@ public: QTextStream stream(&t); while (!stream.atEnd() && !fi.isCanceled()) processLine(stream.readLine(), &resultList); - if (!resultList.isEmpty()) + if (!resultList.isEmpty() && !fi.isCanceled()) fi.reportResult(resultList); } void operator()(FutureInterfaceType &fi) { - Core::ProgressTimer progress(fi, 5); QStringList arguments = { "-c", "color.grep.match=bold red", "-c", "color.grep=always", @@ -168,19 +161,16 @@ public: return QString(":!" + filter); }); arguments << "--" << filterArgs << exclusionArgs; - m_command->addFlags(VcsCommand::SilentOutput); - m_command->setProgressiveOutput(true); - QFutureWatcher watcher; - QObject::connect(&watcher, - &QFutureWatcher::canceled, - m_command.get(), - &VcsCommand::cancel); - watcher.setFuture(fi.future()); - QObject::connect(m_command.get(), - &VcsCommand::stdOutText, - [this, &fi](const QString &text) { read(fi, text); }); - const CommandResult result = m_command->runCommand({m_vcsBinary, arguments}, 0); - switch (result.result()) { + + QtcProcess process; + process.setEnvironment(m_environment); + process.setCommand({m_vcsBinary, arguments}); + process.setWorkingDirectory(m_directory); + process.setStdOutCallback([this, &fi](const QString &text) { read(fi, text); }); + process.start(); + process.waitForFinished(); + + switch (process.result()) { case ProcessResult::TerminatedAbnormally: case ProcessResult::StartFailed: case ProcessResult::Hang: @@ -199,7 +189,7 @@ private: FilePath m_directory; QString m_ref; TextEditor::FileFindParameters m_parameters; - std::unique_ptr m_command; + Environment m_environment; }; } // namespace