BranchModel: Reuse TaskTreeRunner

Change-Id: Idce8e4463e55b9361d85f460a44b7302bf20170f
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Jarek Kobus
2024-01-13 17:27:51 +01:00
parent e0c6ca656c
commit 2a1553bb9a

View File

@@ -7,14 +7,16 @@
#include "gitconstants.h" #include "gitconstants.h"
#include "gittr.h" #include "gittr.h"
#include <vcsbase/vcscommand.h> #include <solutions/tasking/tasktreerunner.h>
#include <vcsbase/vcsoutputwindow.h>
#include <utils/environment.h> #include <utils/environment.h>
#include <utils/process.h> #include <utils/process.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/stringutils.h> #include <utils/stringutils.h>
#include <vcsbase/vcscommand.h>
#include <vcsbase/vcsoutputwindow.h>
#include <QDateTime> #include <QDateTime>
#include <QFont> #include <QFont>
@@ -228,7 +230,7 @@ public:
QString currentSha; QString currentSha;
QDateTime currentDateTime; QDateTime currentDateTime;
QStringList obsoleteLocalBranches; QStringList obsoleteLocalBranches;
std::unique_ptr<TaskTree> refreshTask; TaskTreeRunner taskTreeRunner;
bool oldBranchesIncluded = false; bool oldBranchesIncluded = false;
struct OldEntry struct OldEntry
@@ -254,6 +256,7 @@ BranchModel::BranchModel(QObject *parent) :
// Abuse the sha field for ref prefix // Abuse the sha field for ref prefix
d->rootNode->append(new BranchNode(Tr::tr("Local Branches"), "refs/heads")); d->rootNode->append(new BranchNode(Tr::tr("Local Branches"), "refs/heads"));
d->rootNode->append(new BranchNode(Tr::tr("Remote Branches"), "refs/remotes")); d->rootNode->append(new BranchNode(Tr::tr("Remote Branches"), "refs/remotes"));
connect(&d->taskTreeRunner, &TaskTreeRunner::done, this, &BranchModel::endResetModel);
} }
BranchModel::~BranchModel() BranchModel::~BranchModel()
@@ -402,9 +405,9 @@ void BranchModel::clear()
void BranchModel::refresh(const FilePath &workingDirectory, ShowError showError) void BranchModel::refresh(const FilePath &workingDirectory, ShowError showError)
{ {
if (d->refreshTask) { if (d->taskTreeRunner.isRunning()) {
endResetModel(); // for the running task tree. endResetModel(); // for the running task tree.
d->refreshTask.reset(); // old running tree is reset, no handlers are being called d->taskTreeRunner.reset(); // old running tree is reset, no handlers are being called
} }
beginResetModel(); beginResetModel();
clear(); clear();
@@ -463,18 +466,11 @@ void BranchModel::refresh(const FilePath &workingDirectory, ShowError showError)
} }
}; };
const auto finalize = [this] {
endResetModel();
d->refreshTask.release()->deleteLater();
};
const Group root { const Group root {
topRevisionProc, topRevisionProc,
ProcessTask(onForEachRefSetup, onForEachRefDone), ProcessTask(onForEachRefSetup, onForEachRefDone)
onGroupDone(finalize)
}; };
d->refreshTask.reset(new TaskTree(root)); d->taskTreeRunner.start(root);
d->refreshTask->start();
} }
void BranchModel::setCurrentBranch() void BranchModel::setCurrentBranch()