From 3978cdde6c9c3dc38e67d87cfe58916d6b4095de Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Mon, 19 Sep 2022 08:27:41 +0200 Subject: [PATCH] VcsCommand: Add std channel getters Conform to QtcProcess interface and provide cleanedStdOut() and cleanedStdErr() getters, to be called after the process finished. Use cleanedStdOut() inside DiffEditorController for getting the output after the process finished instead of connecting to stdOutText() signal. Change-Id: I7ba3735b0ab2167ac1f3b0954dd5dc9553910aac Reviewed-by: Orgad Shaneh --- src/plugins/vcsbase/vcsbasediffeditorcontroller.cpp | 9 ++------- src/plugins/vcsbase/vcscommand.cpp | 10 ++++++++++ src/plugins/vcsbase/vcscommand.h | 3 +++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/plugins/vcsbase/vcsbasediffeditorcontroller.cpp b/src/plugins/vcsbase/vcsbasediffeditorcontroller.cpp index 04629f1e8b8..4f8d83ca948 100644 --- a/src/plugins/vcsbase/vcsbasediffeditorcontroller.cpp +++ b/src/plugins/vcsbase/vcsbasediffeditorcontroller.cpp @@ -50,7 +50,6 @@ public: FilePath m_vcsBinary; int m_vscTimeoutS; QString m_startupFile; - QString m_output; QString m_displayName; QPointer m_command; QFutureWatcher> *m_processWatcher = nullptr; @@ -107,12 +106,11 @@ void VcsBaseDiffEditorControllerPrivate::cancelReload() delete m_processWatcher; m_processWatcher = nullptr; } - - m_output = QString(); } void VcsBaseDiffEditorControllerPrivate::commandFinished(bool success) { + const QString output = m_command->cleanedStdOut(); // Don't delete here, as it is called from command finished signal. // Clear it only, as we may call runCommand() again from inside processCommandOutput overload. m_command.clear(); @@ -123,8 +121,7 @@ void VcsBaseDiffEditorControllerPrivate::commandFinished(bool success) return; } - // Pass a copy of m_output since processDiff() cleans the m_output - q->processCommandOutput(QString(m_output)); + q->processCommandOutput(output); } ///////////////////// @@ -151,8 +148,6 @@ void VcsBaseDiffEditorController::runCommand(const QList &args, uns d->m_command = VcsBaseClient::createVcsCommand(workingDirectory(), d->m_processEnvironment); d->m_command->setDisplayName(d->m_displayName); d->m_command->setCodec(codec ? codec : EditorManager::defaultTextCodec()); - connect(d->m_command.data(), &VcsCommand::stdOutText, - this, [this](const QString &output) { d->m_output = output; }); connect(d->m_command.data(), &VcsCommand::finished, this, [this](bool success) { d->commandFinished(success); }); d->m_command->addFlags(flags); diff --git a/src/plugins/vcsbase/vcscommand.cpp b/src/plugins/vcsbase/vcscommand.cpp index 8f9ef8f9b89..0e952a4d852 100644 --- a/src/plugins/vcsbase/vcscommand.cpp +++ b/src/plugins/vcsbase/vcscommand.cpp @@ -372,6 +372,16 @@ void VcsCommand::cancel() emit terminate(); } +QString VcsCommand::cleanedStdOut() const +{ + return d->m_stdOut; +} + +QString VcsCommand::cleanedStdErr() const +{ + return d->m_stdErr; +} + CommandResult VcsCommand::runCommand(const CommandLine &command, int timeoutS) { QtcProcess process; diff --git a/src/plugins/vcsbase/vcscommand.h b/src/plugins/vcsbase/vcscommand.h index cd20d349425..675b707f128 100644 --- a/src/plugins/vcsbase/vcscommand.h +++ b/src/plugins/vcsbase/vcscommand.h @@ -116,6 +116,9 @@ public: CommandResult runCommand(const Utils::CommandLine &command, int timeoutS = 10); void cancel(); + QString cleanedStdOut() const; + QString cleanedStdErr() const; + signals: void stdOutText(const QString &); void stdErrText(const QString &);