diff options
| author | Andre Hartmann <[email protected]> | 2025-05-24 12:17:39 +0200 |
|---|---|---|
| committer | André Hartmann <[email protected]> | 2025-05-25 18:43:45 +0000 |
| commit | b05f87f0bfa6af525e0747e0849fbd6ec4aad884 (patch) | |
| tree | f964a8623ae48a654f402c4e9d11ace27db0c092 /src/plugins/git/gitclient.cpp | |
| parent | 77ef58eb6f164c350801f9a2dcb90dea074251aa (diff) | |
Git: Improve file modification status update
* Do not spawn parallel git processes, queue them and
handle one-by-one
* Change the timer to single shot and restart it after
the last git process ended to avoid overlapping runs
Task-number: QTCREATORBUG-32002
Change-Id: I2731057625406bac66aa8d731e888704b8203328
Reviewed-by: Orgad Shaneh <[email protected]>
Diffstat (limited to 'src/plugins/git/gitclient.cpp')
| -rw-r--r-- | src/plugins/git/gitclient.cpp | 90 |
1 files changed, 53 insertions, 37 deletions
diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp index e43e64b19e6..62c66adb04d 100644 --- a/src/plugins/git/gitclient.cpp +++ b/src/plugins/git/gitclient.cpp @@ -909,55 +909,70 @@ void GitClient::monitorDirectory(const Utils::FilePath &path) void GitClient::updateModificationInfos() { - using IVCF = IVersionControl::FileState; for (const ModificationInfo &infoTemp : std::as_const(m_modifInfos)) { const FilePath path = infoTemp.rootPath; + m_statusUpdateQueue.append(path); + } + updateNextModificationInfo(); +} - const auto command = [path, this](const CommandResult &result) { - if (!m_modifInfos.contains(path)) - return; +void GitClient::updateNextModificationInfo() +{ + using IVCF = IVersionControl::FileState; - ModificationInfo &info = m_modifInfos[path]; + if (m_statusUpdateQueue.isEmpty()) { + m_timer->start(); + return; + } - const QStringList res = result.cleanedStdOut().split("\n", Qt::SkipEmptyParts); - QHash<QString, IVCF> modifiedFiles; - for (const QString &line : res) { - if (line.size() <= 3) - continue; + const FilePath path = m_statusUpdateQueue.dequeue(); + + const auto command = [path, this](const CommandResult &result) { + updateNextModificationInfo(); - static const QHash<QChar, IVCF> gitStates { - {'M', IVCF::ModifiedState}, - {'A', IVCF::AddedState}, - {'R', IVCF::RenamedState}, - {'D', IVCF::DeletedState}, - {'?', IVCF::UnmanagedState}, - }; + if (!m_modifInfos.contains(path)) + return; - const IVCF modification = std::max(gitStates.value(line.at(0), IVCF::NoModification), - gitStates.value(line.at(1), IVCF::NoModification)); + ModificationInfo &info = m_modifInfos[path]; - if (modification != IVCF::NoModification) - modifiedFiles.insert(line.mid(3).trimmed(), modification); - } + const QStringList res = result.cleanedStdOut().split("\n", Qt::SkipEmptyParts); + QHash<QString, IVCF> modifiedFiles; + for (const QString &line : res) { + if (line.size() <= 3) + continue; - const QHash<QString, IVCF> oldfiles = info.modifiedFiles; - info.modifiedFiles = modifiedFiles; + static const QHash<QChar, IVCF> gitStates { + {'M', IVCF::ModifiedState}, + {'A', IVCF::AddedState}, + {'R', IVCF::RenamedState}, + {'D', IVCF::DeletedState}, + {'?', IVCF::UnmanagedState}, + }; - QStringList newList = modifiedFiles.keys(); - QStringList list = oldfiles.keys(); - newList.sort(); - list.sort(); - QStringList statusChangedFiles; + const IVCF modification = std::max(gitStates.value(line.at(0), IVCF::NoModification), + gitStates.value(line.at(1), IVCF::NoModification)); - std::set_symmetric_difference(std::begin(list), std::end(list), - std::begin(newList), std::end(newList), - std::back_inserter(statusChangedFiles)); + if (modification != IVCF::NoModification) + modifiedFiles.insert(line.mid(3).trimmed(), modification); + } - emitFileStatusChanged(info.rootPath, statusChangedFiles); - }; - vcsExecWithHandler(path, {"status", "-s", "--porcelain", "--ignore-submodules"}, - this, command, RunFlags::NoOutput); - } + const QHash<QString, IVCF> oldfiles = info.modifiedFiles; + info.modifiedFiles = modifiedFiles; + + QStringList newList = modifiedFiles.keys(); + QStringList list = oldfiles.keys(); + newList.sort(); + list.sort(); + QStringList statusChangedFiles; + + std::set_symmetric_difference(std::begin(list), std::end(list), + std::begin(newList), std::end(newList), + std::back_inserter(statusChangedFiles)); + + emitFileStatusChanged(info.rootPath, statusChangedFiles); + }; + vcsExecWithHandler(path, {"status", "-s", "--porcelain", "--ignore-submodules"}, + this, command, RunFlags::NoOutput); } TextCodec GitClient::defaultCommitEncoding() const @@ -3911,6 +3926,7 @@ void GitClient::setupTimer() connect(m_timer.get(), &QTimer::timeout, this, &GitClient::updateModificationInfos); using namespace std::chrono_literals; m_timer->setInterval(10s); + m_timer->setSingleShot(true); m_timer->start(); } |
