diff options
| author | Jarek Kobus <[email protected]> | 2022-09-05 18:04:54 +0200 |
|---|---|---|
| committer | Jarek Kobus <[email protected]> | 2022-09-06 14:13:42 +0000 |
| commit | b04b24ca8194f890d4cc8952b670d68a37447f8e (patch) | |
| tree | aea981abcf01398dc926c805dadec8ddc0b48734 /src/plugins/git/gitgrep.cpp | |
| parent | bf0b81f25775533b5b2e56cce79ec4ab95422817 (diff) | |
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 <[email protected]>
Diffstat (limited to 'src/plugins/git/gitgrep.cpp')
| -rw-r--r-- | src/plugins/git/gitgrep.cpp | 40 |
1 files 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 <coreplugin/editormanager/editormanager.h> -#include <coreplugin/progressmanager/progressmanager.h> #include <coreplugin/vcsmanager.h> #include <texteditor/findinfiles.h> #include <vcsbase/vcsbaseconstants.h> -#include <vcsbase/vcscommand.h> #include <utils/algorithm.h> -#include <utils/commandline.h> +#include <utils/environment.h> #include <utils/fancylineedit.h> #include <utils/filesearch.h> -#include <utils/fileutils.h> #include <utils/qtcassert.h> +#include <utils/qtcprocess.h> #include <utils/runextensions.h> -#include <utils/textfileformat.h> #include <QCheckBox> #include <QFuture> -#include <QFutureWatcher> #include <QHBoxLayout> #include <QRegularExpressionValidator> -#include <QScopedPointer> #include <QSettings> #include <QTextStream> @@ -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<FileSearchResultList> watcher; - QObject::connect(&watcher, - &QFutureWatcher<FileSearchResultList>::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<VcsCommand> m_command; + Environment m_environment; }; } // namespace |
