forked from qt-creator/qt-creator
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:
@@ -416,7 +416,7 @@ void BranchModel::refresh(const FilePath &workingDirectory, ShowError showError)
|
||||
d->currentDateTime = dateTime;
|
||||
});
|
||||
|
||||
const auto setupForEachRef = [this, workingDirectory](Process &process) {
|
||||
const auto onForEachRefSetup = [this, workingDirectory](Process &process) {
|
||||
d->workingDirectory = workingDirectory;
|
||||
QStringList args = {"for-each-ref",
|
||||
"--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);
|
||||
};
|
||||
|
||||
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 QStringList lines = output.split('\n');
|
||||
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] {
|
||||
endResetModel();
|
||||
d->refreshTask.release()->deleteLater();
|
||||
@@ -466,7 +467,7 @@ void BranchModel::refresh(const FilePath &workingDirectory, ShowError showError)
|
||||
|
||||
const Group root {
|
||||
topRevisionProc,
|
||||
ProcessTask(setupForEachRef, forEachRefDone, forEachRefError),
|
||||
ProcessTask(onForEachRefSetup, onForEachRefDone),
|
||||
onGroupDone(finalize),
|
||||
onGroupError(finalize)
|
||||
};
|
||||
|
@@ -391,7 +391,7 @@ ShowController::ShowController(IDocument *document, const QString &id)
|
||||
setDescription(desc);
|
||||
};
|
||||
|
||||
const auto setupDescription = [this, id](Process &process) {
|
||||
const auto onDescriptionSetup = [this, id](Process &process) {
|
||||
process.setCodec(gitClient().encoding(GitClient::EncodingCommit, workingDirectory()));
|
||||
setupCommand(process, {"show", "-s", noColorOption, showFormatC, id});
|
||||
VcsOutputWindow::appendCommand(process.workingDirectory(), process.commandLine());
|
||||
@@ -418,72 +418,68 @@ ShowController::ShowController(IDocument *document, const QString &id)
|
||||
return SetupResult::Continue;
|
||||
};
|
||||
|
||||
const auto setupBranches = [this, storage](Process &process) {
|
||||
const auto onBranchesSetup = [this, storage](Process &process) {
|
||||
storage->m_branches = busyMessage;
|
||||
setupCommand(process, {"branch", noColorOption, "-a", "--contains", storage->m_commit});
|
||||
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();
|
||||
data->m_branches.clear();
|
||||
const QString remotePrefix = "remotes/";
|
||||
const QString localPrefix = "<Local>";
|
||||
const int prefixLength = remotePrefix.length();
|
||||
QStringList branches;
|
||||
QString previousRemote = localPrefix;
|
||||
bool first = true;
|
||||
const QStringList branchList = process.cleanedStdOut().split('\n');
|
||||
for (const QString &branch : branchList) {
|
||||
const QString b = branch.mid(2).trimmed();
|
||||
if (b.isEmpty())
|
||||
continue;
|
||||
if (b.startsWith(remotePrefix)) {
|
||||
const int nextSlash = b.indexOf('/', prefixLength);
|
||||
if (nextSlash < 0)
|
||||
if (success) {
|
||||
const QString remotePrefix = "remotes/";
|
||||
const QString localPrefix = "<Local>";
|
||||
const int prefixLength = remotePrefix.length();
|
||||
QStringList branches;
|
||||
QString previousRemote = localPrefix;
|
||||
bool first = true;
|
||||
const QStringList branchList = process.cleanedStdOut().split('\n');
|
||||
for (const QString &branch : branchList) {
|
||||
const QString b = branch.mid(2).trimmed();
|
||||
if (b.isEmpty())
|
||||
continue;
|
||||
const QString remote = b.mid(prefixLength, nextSlash - prefixLength);
|
||||
if (remote != previousRemote) {
|
||||
data->m_branches += branchesDisplay(previousRemote, &branches, &first) + '\n';
|
||||
branches.clear();
|
||||
previousRemote = remote;
|
||||
if (b.startsWith(remotePrefix)) {
|
||||
const int nextSlash = b.indexOf('/', prefixLength);
|
||||
if (nextSlash < 0)
|
||||
continue;
|
||||
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);
|
||||
};
|
||||
|
||||
const auto setupPrecedes = [this, storage](Process &process) {
|
||||
const auto onPrecedesSetup = [this, storage](Process &process) {
|
||||
storage->m_precedes = busyMessage;
|
||||
setupCommand(process, {"describe", "--contains", storage->m_commit});
|
||||
};
|
||||
const auto onPrecedesDone = [storage, updateDescription](const Process &process) {
|
||||
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 &) {
|
||||
const auto onPrecedesDone = [storage, updateDescription](const Process &process, bool success) {
|
||||
ReloadStorage *data = storage.activeStorage();
|
||||
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);
|
||||
};
|
||||
|
||||
@@ -516,7 +512,7 @@ ShowController::ShowController(IDocument *document, const QString &id)
|
||||
taskTree.setRecipe(tasks);
|
||||
};
|
||||
|
||||
const auto setupDiff = [this, id](Process &process) {
|
||||
const auto onDiffSetup = [this, id](Process &process) {
|
||||
setupCommand(process, addConfigurationArguments(
|
||||
{"show", "--format=format:", // omit header, already generated
|
||||
noColorOption, decorateOption, id}));
|
||||
@@ -533,18 +529,18 @@ ShowController::ShowController(IDocument *document, const QString &id)
|
||||
onGroupSetup([this] { setStartupFile(VcsBase::source(this->document()).toString()); }),
|
||||
Group {
|
||||
finishAllAndDone,
|
||||
ProcessTask(setupDescription, onDescriptionDone),
|
||||
ProcessTask(onDescriptionSetup, onDescriptionDone),
|
||||
Group {
|
||||
parallel,
|
||||
finishAllAndDone,
|
||||
onGroupSetup(desciptionDetailsSetup),
|
||||
ProcessTask(setupBranches, onBranchesDone, onBranchesError),
|
||||
ProcessTask(setupPrecedes, onPrecedesDone, onPrecedesError),
|
||||
ProcessTask(onBranchesSetup, onBranchesDone),
|
||||
ProcessTask(onPrecedesSetup, onPrecedesDone),
|
||||
TaskTreeTask(setupFollows)
|
||||
}
|
||||
},
|
||||
Group {
|
||||
ProcessTask(setupDiff, onDiffDone),
|
||||
ProcessTask(onDiffSetup, onDiffDone),
|
||||
postProcessTask(diffInputStorage)
|
||||
}
|
||||
};
|
||||
|
@@ -165,7 +165,7 @@ SubversionDiffEditorController::SubversionDiffEditorController(IDocument *docume
|
||||
|
||||
const TreeStorage<QString> diffInputStorage;
|
||||
|
||||
const auto setupDescription = [this](Process &process) {
|
||||
const auto onDescriptionSetup = [this](Process &process) {
|
||||
if (m_changeNumber == 0)
|
||||
return SetupResult::StopWithDone;
|
||||
setupCommand(process, {"log", "-r", QString::number(m_changeNumber)});
|
||||
@@ -175,14 +175,11 @@ SubversionDiffEditorController::SubversionDiffEditorController(IDocument *docume
|
||||
setDescription(Tr::tr("Waiting for data..."));
|
||||
return SetupResult::Continue;
|
||||
};
|
||||
const auto onDescriptionDone = [this](const Process &process) {
|
||||
setDescription(process.cleanedStdOut());
|
||||
};
|
||||
const auto onDescriptionError = [this](const Process &) {
|
||||
setDescription({});
|
||||
const auto onDescriptionDone = [this](const Process &process, bool success) {
|
||||
setDescription(success ? process.cleanedStdOut() : QString());
|
||||
};
|
||||
|
||||
const auto setupDiff = [this](Process &process) {
|
||||
const auto onDiffSetup = [this](Process &process) {
|
||||
QStringList args = QStringList{"diff"} << "--internal-diff";
|
||||
if (ignoreWhitespace())
|
||||
args << "-x" << "-uw";
|
||||
@@ -205,10 +202,10 @@ SubversionDiffEditorController::SubversionDiffEditorController(IDocument *docume
|
||||
parallel,
|
||||
Group {
|
||||
finishAllAndDone,
|
||||
ProcessTask(setupDescription, onDescriptionDone, onDescriptionError)
|
||||
ProcessTask(onDescriptionSetup, onDescriptionDone)
|
||||
},
|
||||
Group {
|
||||
ProcessTask(setupDiff, onDiffDone),
|
||||
ProcessTask(onDiffSetup, onDiffDone),
|
||||
postProcessTask(diffInputStorage)
|
||||
}
|
||||
};
|
||||
|
@@ -40,18 +40,15 @@ VcsBaseDiffEditorController::~VcsBaseDiffEditorController()
|
||||
|
||||
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.setConcurrentCallData(&DiffUtils::readPatchWithPromise, *inputStorage);
|
||||
};
|
||||
const auto onDiffProcessorDone = [this](const Async<QList<FileData>> &async) {
|
||||
setDiffFiles(async.isResultAvailable() ? async.result() : QList<FileData>());
|
||||
const auto onDone = [this](const Async<QList<FileData>> &async, bool success) {
|
||||
setDiffFiles(success && async.isResultAvailable() ? async.result() : QList<FileData>());
|
||||
// TODO: We should set the right starting line here
|
||||
};
|
||||
const auto onDiffProcessorError = [this](const Async<QList<FileData>> &) {
|
||||
setDiffFiles({});
|
||||
};
|
||||
return AsyncTask<QList<FileData>>(setupDiffProcessor, onDiffProcessorDone, onDiffProcessorError);
|
||||
return AsyncTask<QList<FileData>>(onSetup, onDone);
|
||||
}
|
||||
|
||||
void VcsBaseDiffEditorController::setupCommand(Process &process, const QStringList &args) const
|
||||
|
Reference in New Issue
Block a user