diff options
author | Jarek Kobus <jaroslaw.kobus@qt.io> | 2022-12-08 18:50:54 +0100 |
---|---|---|
committer | Jarek Kobus <jaroslaw.kobus@qt.io> | 2022-12-09 10:29:04 +0000 |
commit | 287a7c92689628bb05c8ca4a26289b49d8440a05 (patch) | |
tree | 9323f4acb78a2b4c4a9efee1cd5ac6e3f4612328 /src/plugins/git/gitplugin.cpp | |
parent | c08317b5a673b7bb57de9a6801169975a3dc80ef (diff) | |
download | qt-creator-287a7c92689628bb05c8ca4a26289b49d8440a05.tar.gz |
VcsBase: Introduce vcsExecWithHandler()
Before, vcsExec() returned already started VcsCommand.
Later, callers of vcsExec() were establishing connections
to the retured VcsCommand::done() signal. However, when
process fails to start (e.g. because of non-existing
executable), the done() signal may be emitted synchonously
from inside VcsCommand::start(). In this scenario
callers of VcsCommand could miss the emission of done()
signal and connect to already finished command.
Instead, provide a vcsExecWithHandler() function which
takes a handler to be called when command finished.
In addition it takes the context object, too.
Don't return VcsCommand from vcsExec() anymore.
Change-Id: I2fb5fbe5d27632ea039c650d37e5d7d1b60cebc0
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Diffstat (limited to 'src/plugins/git/gitplugin.cpp')
-rw-r--r-- | src/plugins/git/gitplugin.cpp | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/plugins/git/gitplugin.cpp b/src/plugins/git/gitplugin.cpp index ae3c98b42b..974dde851f 100644 --- a/src/plugins/git/gitplugin.cpp +++ b/src/plugins/git/gitplugin.cpp @@ -1572,19 +1572,19 @@ void GitPluginPrivate::instantBlame() const QFileInfo fi(filePath.toString()); const Utils::FilePath workingDirectory = Utils::FilePath::fromString(fi.path()); const QString lineString = QString("%1,%1").arg(line); - const VcsCommand *command = GitClient::instance()->vcsExec( - workingDirectory, {"blame", "-p", "-L", lineString, "--", filePath.toString()}, - nullptr, false, RunFlags::NoOutput); - connect(command, &VcsCommand::done, this, [command, filePath, line, this] { - if (command->result() == ProcessResult::FinishedWithError && - command->cleanedStdErr().contains("no such path")) { + const auto commandHandler = [this, filePath, line](const CommandResult &result) { + if (result.result() == ProcessResult::FinishedWithError && + result.cleanedStdErr().contains("no such path")) { disconnect(m_blameCursorPosConn); return; } - const QString output = command->cleanedStdOut(); + const QString output = result.cleanedStdOut(); const CommitInfo info = parseBlameOutput(output.split('\n'), filePath, m_author); m_blameMark.reset(new BlameMark(filePath, line, info)); - }); + }; + GitClient::instance()->vcsExecWithHandler(workingDirectory, + {"blame", "-p", "-L", lineString, "--", filePath.toString()}, + this, commandHandler, RunFlags::NoOutput, false); } void GitPluginPrivate::stopInstantBlame() |