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>
This commit is contained in:
Jarek Kobus
2022-12-08 18:50:54 +01:00
parent c08317b5a6
commit 287a7c9268
11 changed files with 193 additions and 167 deletions

View File

@@ -416,28 +416,25 @@ bool BranchView::checkout()
return false;
}
VcsCommand *command = m_model->checkoutBranch(selected);
const bool moveChanges = branchCheckoutDialog.moveLocalChangesToNextBranch();
const bool popStash = branchCheckoutDialog.popStashOfNextBranch();
if (command && (moveChanges || popStash)) {
connect(command, &VcsCommand::done,
this, [this, client, popMessageStart, moveChanges, popStash] {
if (moveChanges) {
client->endStashScope(m_repository);
} else if (popStash) {
QList<Stash> stashes;
QString stashName;
client->synchronousStashList(m_repository, &stashes);
for (const Stash &stash : std::as_const(stashes)) {
if (stash.message.startsWith(popMessageStart)) {
stashName = stash.name;
break;
}
const auto commandHandler = [=](const CommandResult &) {
if (moveChanges) {
client->endStashScope(m_repository);
} else if (popStash) {
QList<Stash> stashes;
QString stashName;
client->synchronousStashList(m_repository, &stashes);
for (const Stash &stash : std::as_const(stashes)) {
if (stash.message.startsWith(popMessageStart)) {
stashName = stash.name;
break;
}
client->synchronousStashRestore(m_repository, stashName, true);
}
});
}
client->synchronousStashRestore(m_repository, stashName, true);
}
};
m_model->checkoutBranch(selected, this, commandHandler);
}
if (QTC_GUARD(m_branchView))