forked from qt-creator/qt-creator
FileListDiffController: Reuse task tree
This makes it possible that staged and unstaged tasks are run in parallel, so the result is to be expected earlier. Change-Id: I0b99d17a55e39f2178d6ebed208e29fbaaa8aa5e Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -223,23 +223,80 @@ class FileListDiffController : public GitBaseDiffEditorController
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FileListDiffController(IDocument *document,
|
FileListDiffController(IDocument *document,
|
||||||
const QStringList &stagedFiles, const QStringList &unstagedFiles) :
|
const QStringList &stagedFiles, const QStringList &unstagedFiles)
|
||||||
GitBaseDiffEditorController(document, {}, {})
|
: GitBaseDiffEditorController(document, {}, {})
|
||||||
|
, m_stagedFiles(stagedFiles)
|
||||||
|
, m_unstagedFiles(unstagedFiles)
|
||||||
{
|
{
|
||||||
setReloader([this, stagedFiles, unstagedFiles] {
|
|
||||||
QList<QStringList> argLists;
|
|
||||||
if (!stagedFiles.isEmpty()) {
|
|
||||||
QStringList stagedArgs = QStringList({"diff", "--cached", "--"}) << stagedFiles;
|
|
||||||
argLists << addConfigurationArguments(stagedArgs);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!unstagedFiles.isEmpty())
|
|
||||||
argLists << addConfigurationArguments(baseArguments() << "--" << unstagedFiles);
|
|
||||||
|
|
||||||
if (!argLists.isEmpty())
|
|
||||||
runCommand(argLists, VcsBaseEditor::getCodec(workingDirectory(), stagedFiles + unstagedFiles));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
private:
|
||||||
|
Tasking::Group reloadRecipe() final
|
||||||
|
{
|
||||||
|
using namespace Tasking;
|
||||||
|
|
||||||
|
struct DiffStorage {
|
||||||
|
QString m_stagedOutput;
|
||||||
|
QString m_unstagedOutput;
|
||||||
|
};
|
||||||
|
|
||||||
|
const TreeStorage<DiffStorage> storage;
|
||||||
|
|
||||||
|
const auto setupStaged = [this](QtcProcess &process) {
|
||||||
|
process.setCodec(VcsBaseEditor::getCodec(workingDirectory(), m_stagedFiles));
|
||||||
|
setupCommand(process, addConfigurationArguments(
|
||||||
|
QStringList({"diff", "--cached", "--"}) + m_stagedFiles));
|
||||||
|
VcsOutputWindow::appendCommand(process.workingDirectory(), process.commandLine());
|
||||||
|
};
|
||||||
|
const auto onStagedDone = [storage](const QtcProcess &process) {
|
||||||
|
storage->m_stagedOutput = process.cleanedStdOut();
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto setupUnstaged = [this](QtcProcess &process) {
|
||||||
|
process.setCodec(VcsBaseEditor::getCodec(workingDirectory(), m_unstagedFiles));
|
||||||
|
setupCommand(process, addConfigurationArguments(
|
||||||
|
QStringList({"diff", "--"}) + m_unstagedFiles));
|
||||||
|
VcsOutputWindow::appendCommand(process.workingDirectory(), process.commandLine());
|
||||||
|
};
|
||||||
|
const auto onUnstagedDone = [storage](const QtcProcess &process) {
|
||||||
|
storage->m_unstagedOutput = process.cleanedStdOut();
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto onStagingDynamicSetup = [this] {
|
||||||
|
setStartupFile(VcsBase::source(document()));
|
||||||
|
QSet<int> config;
|
||||||
|
if (!m_stagedFiles.isEmpty())
|
||||||
|
config.insert(0);
|
||||||
|
if (!m_unstagedFiles.isEmpty())
|
||||||
|
config.insert(1);
|
||||||
|
return GroupConfig{GroupAction::ContinueSelected, config};
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto setupProcessDiff = [this, storage](AsyncTask<QList<FileData>> &async) {
|
||||||
|
setupDiffProcessor(async, storage->m_stagedOutput + storage->m_unstagedOutput);
|
||||||
|
};
|
||||||
|
const auto onProcessDiffDone = [this, storage](const AsyncTask<QList<FileData>> &async) {
|
||||||
|
setDiffFiles(async.result(), workingDirectory(), startupFile());
|
||||||
|
};
|
||||||
|
const auto onProcessDiffError = [this, storage](const AsyncTask<QList<FileData>> &) {
|
||||||
|
setDiffFiles({}, workingDirectory(), startupFile());
|
||||||
|
};
|
||||||
|
|
||||||
|
const Group root {
|
||||||
|
Storage(storage),
|
||||||
|
Group {
|
||||||
|
parallel,
|
||||||
|
optional,
|
||||||
|
DynamicSetup(onStagingDynamicSetup),
|
||||||
|
Process(setupStaged, onStagedDone),
|
||||||
|
Process(setupUnstaged, onUnstagedDone)
|
||||||
|
},
|
||||||
|
Async<QList<FileData>>(setupProcessDiff, onProcessDiffDone, onProcessDiffError)
|
||||||
|
};
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList m_stagedFiles;
|
||||||
|
QStringList m_unstagedFiles;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ShowController : public GitBaseDiffEditorController
|
class ShowController : public GitBaseDiffEditorController
|
||||||
|
Reference in New Issue
Block a user