VcsBase: Use common done handler

Instead of specifying two separate done and error handlers,
specify just one that takes additional "bool success" argument.

Task-number: QTCREATORBUG-29834
Change-Id: Ib92ef2dcd960372d9db6c8f50d4017a33c49ccd3
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
Jarek Kobus
2023-10-31 17:55:22 +01:00
parent 6059164299
commit 0e7ecee489
4 changed files with 74 additions and 83 deletions

View File

@@ -416,7 +416,7 @@ void BranchModel::refresh(const FilePath &workingDirectory, ShowError showError)
d->currentDateTime = dateTime; d->currentDateTime = dateTime;
}); });
const auto setupForEachRef = [this, workingDirectory](Process &process) { const auto onForEachRefSetup = [this, workingDirectory](Process &process) {
d->workingDirectory = workingDirectory; d->workingDirectory = workingDirectory;
QStringList args = {"for-each-ref", QStringList args = {"for-each-ref",
"--format=%(objectname)\t%(refname)\t%(upstream:short)\t" "--format=%(objectname)\t%(refname)\t%(upstream:short)\t"
@@ -428,7 +428,18 @@ void BranchModel::refresh(const FilePath &workingDirectory, ShowError showError)
gitClient().setupCommand(process, workingDirectory, args); gitClient().setupCommand(process, workingDirectory, args);
}; };
const auto forEachRefDone = [this](const Process &process) { const auto onForEachRefDone = [this, workingDirectory, showError](const Process &process,
bool success) {
if (!success) {
if (showError == ShowError::No)
return;
const QString message = Tr::tr("Cannot run \"%1\" in \"%2\": %3")
.arg("git for-each-ref")
.arg(workingDirectory.toUserOutput())
.arg(process.cleanedStdErr());
VcsBase::VcsOutputWindow::appendError(message);
return;
}
const QString output = process.stdOut(); const QString output = process.stdOut();
const QStringList lines = output.split('\n'); const QStringList lines = output.split('\n');
for (const QString &l : lines) for (const QString &l : lines)
@@ -449,16 +460,6 @@ void BranchModel::refresh(const FilePath &workingDirectory, ShowError showError)
} }
}; };
const auto forEachRefError = [workingDirectory, showError](const Process &process) {
if (showError == ShowError::No)
return;
const QString message = Tr::tr("Cannot run \"%1\" in \"%2\": %3")
.arg("git for-each-ref")
.arg(workingDirectory.toUserOutput())
.arg(process.cleanedStdErr());
VcsBase::VcsOutputWindow::appendError(message);
};
const auto finalize = [this] { const auto finalize = [this] {
endResetModel(); endResetModel();
d->refreshTask.release()->deleteLater(); d->refreshTask.release()->deleteLater();
@@ -466,7 +467,7 @@ void BranchModel::refresh(const FilePath &workingDirectory, ShowError showError)
const Group root { const Group root {
topRevisionProc, topRevisionProc,
ProcessTask(setupForEachRef, forEachRefDone, forEachRefError), ProcessTask(onForEachRefSetup, onForEachRefDone),
onGroupDone(finalize), onGroupDone(finalize),
onGroupError(finalize) onGroupError(finalize)
}; };

View File

@@ -391,7 +391,7 @@ ShowController::ShowController(IDocument *document, const QString &id)
setDescription(desc); setDescription(desc);
}; };
const auto setupDescription = [this, id](Process &process) { const auto onDescriptionSetup = [this, id](Process &process) {
process.setCodec(gitClient().encoding(GitClient::EncodingCommit, workingDirectory())); process.setCodec(gitClient().encoding(GitClient::EncodingCommit, workingDirectory()));
setupCommand(process, {"show", "-s", noColorOption, showFormatC, id}); setupCommand(process, {"show", "-s", noColorOption, showFormatC, id});
VcsOutputWindow::appendCommand(process.workingDirectory(), process.commandLine()); VcsOutputWindow::appendCommand(process.workingDirectory(), process.commandLine());
@@ -418,72 +418,68 @@ ShowController::ShowController(IDocument *document, const QString &id)
return SetupResult::Continue; return SetupResult::Continue;
}; };
const auto setupBranches = [this, storage](Process &process) { const auto onBranchesSetup = [this, storage](Process &process) {
storage->m_branches = busyMessage; storage->m_branches = busyMessage;
setupCommand(process, {"branch", noColorOption, "-a", "--contains", storage->m_commit}); setupCommand(process, {"branch", noColorOption, "-a", "--contains", storage->m_commit});
VcsOutputWindow::appendCommand(process.workingDirectory(), process.commandLine()); VcsOutputWindow::appendCommand(process.workingDirectory(), process.commandLine());
}; };
const auto onBranchesDone = [storage, updateDescription](const Process &process) { const auto onBranchesDone = [storage, updateDescription](const Process &process, bool success) {
ReloadStorage *data = storage.activeStorage(); ReloadStorage *data = storage.activeStorage();
data->m_branches.clear(); data->m_branches.clear();
const QString remotePrefix = "remotes/"; if (success) {
const QString localPrefix = "<Local>"; const QString remotePrefix = "remotes/";
const int prefixLength = remotePrefix.length(); const QString localPrefix = "<Local>";
QStringList branches; const int prefixLength = remotePrefix.length();
QString previousRemote = localPrefix; QStringList branches;
bool first = true; QString previousRemote = localPrefix;
const QStringList branchList = process.cleanedStdOut().split('\n'); bool first = true;
for (const QString &branch : branchList) { const QStringList branchList = process.cleanedStdOut().split('\n');
const QString b = branch.mid(2).trimmed(); for (const QString &branch : branchList) {
if (b.isEmpty()) const QString b = branch.mid(2).trimmed();
continue; if (b.isEmpty())
if (b.startsWith(remotePrefix)) {
const int nextSlash = b.indexOf('/', prefixLength);
if (nextSlash < 0)
continue; continue;
const QString remote = b.mid(prefixLength, nextSlash - prefixLength); if (b.startsWith(remotePrefix)) {
if (remote != previousRemote) { const int nextSlash = b.indexOf('/', prefixLength);
data->m_branches += branchesDisplay(previousRemote, &branches, &first) + '\n'; if (nextSlash < 0)
branches.clear(); continue;
previousRemote = remote; const QString remote = b.mid(prefixLength, nextSlash - prefixLength);
if (remote != previousRemote) {
data->m_branches += branchesDisplay(previousRemote, &branches, &first)
+ '\n';
branches.clear();
previousRemote = remote;
}
branches << b.mid(nextSlash + 1);
} else {
branches << b;
} }
branches << b.mid(nextSlash + 1);
} else {
branches << b;
} }
if (branches.isEmpty()) {
if (previousRemote == localPrefix)
data->m_branches += Tr::tr("<None>");
} else {
data->m_branches += branchesDisplay(previousRemote, &branches, &first);
}
data->m_branches = data->m_branches.trimmed();
} }
if (branches.isEmpty()) {
if (previousRemote == localPrefix)
data->m_branches += Tr::tr("<None>");
} else {
data->m_branches += branchesDisplay(previousRemote, &branches, &first);
}
data->m_branches = data->m_branches.trimmed();
updateDescription(*data);
};
const auto onBranchesError = [storage, updateDescription](const Process &) {
ReloadStorage *data = storage.activeStorage();
data->m_branches.clear();
updateDescription(*data); updateDescription(*data);
}; };
const auto setupPrecedes = [this, storage](Process &process) { const auto onPrecedesSetup = [this, storage](Process &process) {
storage->m_precedes = busyMessage; storage->m_precedes = busyMessage;
setupCommand(process, {"describe", "--contains", storage->m_commit}); setupCommand(process, {"describe", "--contains", storage->m_commit});
}; };
const auto onPrecedesDone = [storage, updateDescription](const Process &process) { const auto onPrecedesDone = [storage, updateDescription](const Process &process, bool success) {
ReloadStorage *data = storage.activeStorage();
data->m_precedes = process.cleanedStdOut().trimmed();
const int tilde = data->m_precedes.indexOf('~');
if (tilde != -1)
data->m_precedes.truncate(tilde);
if (data->m_precedes.endsWith("^0"))
data->m_precedes.chop(2);
updateDescription(*data);
};
const auto onPrecedesError = [storage, updateDescription](const Process &) {
ReloadStorage *data = storage.activeStorage(); ReloadStorage *data = storage.activeStorage();
data->m_precedes.clear(); data->m_precedes.clear();
if (success) {
data->m_precedes = process.cleanedStdOut().trimmed();
const int tilde = data->m_precedes.indexOf('~');
if (tilde != -1)
data->m_precedes.truncate(tilde);
if (data->m_precedes.endsWith("^0"))
data->m_precedes.chop(2);
}
updateDescription(*data); updateDescription(*data);
}; };
@@ -516,7 +512,7 @@ ShowController::ShowController(IDocument *document, const QString &id)
taskTree.setRecipe(tasks); taskTree.setRecipe(tasks);
}; };
const auto setupDiff = [this, id](Process &process) { const auto onDiffSetup = [this, id](Process &process) {
setupCommand(process, addConfigurationArguments( setupCommand(process, addConfigurationArguments(
{"show", "--format=format:", // omit header, already generated {"show", "--format=format:", // omit header, already generated
noColorOption, decorateOption, id})); noColorOption, decorateOption, id}));
@@ -533,18 +529,18 @@ ShowController::ShowController(IDocument *document, const QString &id)
onGroupSetup([this] { setStartupFile(VcsBase::source(this->document()).toString()); }), onGroupSetup([this] { setStartupFile(VcsBase::source(this->document()).toString()); }),
Group { Group {
finishAllAndDone, finishAllAndDone,
ProcessTask(setupDescription, onDescriptionDone), ProcessTask(onDescriptionSetup, onDescriptionDone),
Group { Group {
parallel, parallel,
finishAllAndDone, finishAllAndDone,
onGroupSetup(desciptionDetailsSetup), onGroupSetup(desciptionDetailsSetup),
ProcessTask(setupBranches, onBranchesDone, onBranchesError), ProcessTask(onBranchesSetup, onBranchesDone),
ProcessTask(setupPrecedes, onPrecedesDone, onPrecedesError), ProcessTask(onPrecedesSetup, onPrecedesDone),
TaskTreeTask(setupFollows) TaskTreeTask(setupFollows)
} }
}, },
Group { Group {
ProcessTask(setupDiff, onDiffDone), ProcessTask(onDiffSetup, onDiffDone),
postProcessTask(diffInputStorage) postProcessTask(diffInputStorage)
} }
}; };

View File

@@ -165,7 +165,7 @@ SubversionDiffEditorController::SubversionDiffEditorController(IDocument *docume
const TreeStorage<QString> diffInputStorage; const TreeStorage<QString> diffInputStorage;
const auto setupDescription = [this](Process &process) { const auto onDescriptionSetup = [this](Process &process) {
if (m_changeNumber == 0) if (m_changeNumber == 0)
return SetupResult::StopWithDone; return SetupResult::StopWithDone;
setupCommand(process, {"log", "-r", QString::number(m_changeNumber)}); setupCommand(process, {"log", "-r", QString::number(m_changeNumber)});
@@ -175,14 +175,11 @@ SubversionDiffEditorController::SubversionDiffEditorController(IDocument *docume
setDescription(Tr::tr("Waiting for data...")); setDescription(Tr::tr("Waiting for data..."));
return SetupResult::Continue; return SetupResult::Continue;
}; };
const auto onDescriptionDone = [this](const Process &process) { const auto onDescriptionDone = [this](const Process &process, bool success) {
setDescription(process.cleanedStdOut()); setDescription(success ? process.cleanedStdOut() : QString());
};
const auto onDescriptionError = [this](const Process &) {
setDescription({});
}; };
const auto setupDiff = [this](Process &process) { const auto onDiffSetup = [this](Process &process) {
QStringList args = QStringList{"diff"} << "--internal-diff"; QStringList args = QStringList{"diff"} << "--internal-diff";
if (ignoreWhitespace()) if (ignoreWhitespace())
args << "-x" << "-uw"; args << "-x" << "-uw";
@@ -205,10 +202,10 @@ SubversionDiffEditorController::SubversionDiffEditorController(IDocument *docume
parallel, parallel,
Group { Group {
finishAllAndDone, finishAllAndDone,
ProcessTask(setupDescription, onDescriptionDone, onDescriptionError) ProcessTask(onDescriptionSetup, onDescriptionDone)
}, },
Group { Group {
ProcessTask(setupDiff, onDiffDone), ProcessTask(onDiffSetup, onDiffDone),
postProcessTask(diffInputStorage) postProcessTask(diffInputStorage)
} }
}; };

View File

@@ -40,18 +40,15 @@ VcsBaseDiffEditorController::~VcsBaseDiffEditorController()
GroupItem VcsBaseDiffEditorController::postProcessTask(const TreeStorage<QString> &inputStorage) GroupItem VcsBaseDiffEditorController::postProcessTask(const TreeStorage<QString> &inputStorage)
{ {
const auto setupDiffProcessor = [inputStorage](Async<QList<FileData>> &async) { const auto onSetup = [inputStorage](Async<QList<FileData>> &async) {
async.setFutureSynchronizer(ExtensionSystem::PluginManager::futureSynchronizer()); async.setFutureSynchronizer(ExtensionSystem::PluginManager::futureSynchronizer());
async.setConcurrentCallData(&DiffUtils::readPatchWithPromise, *inputStorage); async.setConcurrentCallData(&DiffUtils::readPatchWithPromise, *inputStorage);
}; };
const auto onDiffProcessorDone = [this](const Async<QList<FileData>> &async) { const auto onDone = [this](const Async<QList<FileData>> &async, bool success) {
setDiffFiles(async.isResultAvailable() ? async.result() : QList<FileData>()); setDiffFiles(success && async.isResultAvailable() ? async.result() : QList<FileData>());
// TODO: We should set the right starting line here // TODO: We should set the right starting line here
}; };
const auto onDiffProcessorError = [this](const Async<QList<FileData>> &) { return AsyncTask<QList<FileData>>(onSetup, onDone);
setDiffFiles({});
};
return AsyncTask<QList<FileData>>(setupDiffProcessor, onDiffProcessorDone, onDiffProcessorError);
} }
void VcsBaseDiffEditorController::setupCommand(Process &process, const QStringList &args) const void VcsBaseDiffEditorController::setupCommand(Process &process, const QStringList &args) const