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 <orgads@gmail.com>
This commit is contained in:
Jarek Kobus
2022-09-19 08:27:41 +02:00
parent 5b0c2bcbf8
commit 3978cdde6c
3 changed files with 15 additions and 7 deletions

View File

@@ -50,7 +50,6 @@ public:
FilePath m_vcsBinary; FilePath m_vcsBinary;
int m_vscTimeoutS; int m_vscTimeoutS;
QString m_startupFile; QString m_startupFile;
QString m_output;
QString m_displayName; QString m_displayName;
QPointer<VcsCommand> m_command; QPointer<VcsCommand> m_command;
QFutureWatcher<QList<FileData>> *m_processWatcher = nullptr; QFutureWatcher<QList<FileData>> *m_processWatcher = nullptr;
@@ -107,12 +106,11 @@ void VcsBaseDiffEditorControllerPrivate::cancelReload()
delete m_processWatcher; delete m_processWatcher;
m_processWatcher = nullptr; m_processWatcher = nullptr;
} }
m_output = QString();
} }
void VcsBaseDiffEditorControllerPrivate::commandFinished(bool success) void VcsBaseDiffEditorControllerPrivate::commandFinished(bool success)
{ {
const QString output = m_command->cleanedStdOut();
// Don't delete here, as it is called from command finished signal. // 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. // Clear it only, as we may call runCommand() again from inside processCommandOutput overload.
m_command.clear(); m_command.clear();
@@ -123,8 +121,7 @@ void VcsBaseDiffEditorControllerPrivate::commandFinished(bool success)
return; return;
} }
// Pass a copy of m_output since processDiff() cleans the m_output q->processCommandOutput(output);
q->processCommandOutput(QString(m_output));
} }
///////////////////// /////////////////////
@@ -151,8 +148,6 @@ void VcsBaseDiffEditorController::runCommand(const QList<QStringList> &args, uns
d->m_command = VcsBaseClient::createVcsCommand(workingDirectory(), d->m_processEnvironment); d->m_command = VcsBaseClient::createVcsCommand(workingDirectory(), d->m_processEnvironment);
d->m_command->setDisplayName(d->m_displayName); d->m_command->setDisplayName(d->m_displayName);
d->m_command->setCodec(codec ? codec : EditorManager::defaultTextCodec()); 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, connect(d->m_command.data(), &VcsCommand::finished,
this, [this](bool success) { d->commandFinished(success); }); this, [this](bool success) { d->commandFinished(success); });
d->m_command->addFlags(flags); d->m_command->addFlags(flags);

View File

@@ -372,6 +372,16 @@ void VcsCommand::cancel()
emit terminate(); 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) CommandResult VcsCommand::runCommand(const CommandLine &command, int timeoutS)
{ {
QtcProcess process; QtcProcess process;

View File

@@ -116,6 +116,9 @@ public:
CommandResult runCommand(const Utils::CommandLine &command, int timeoutS = 10); CommandResult runCommand(const Utils::CommandLine &command, int timeoutS = 10);
void cancel(); void cancel();
QString cleanedStdOut() const;
QString cleanedStdErr() const;
signals: signals:
void stdOutText(const QString &); void stdOutText(const QString &);
void stdErrText(const QString &); void stdErrText(const QString &);