From 8394bb0a2b6801405a48207f301f0efb66f2debe Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Tue, 11 Oct 2022 16:28:02 +0300 Subject: [PATCH] Git: Improve tracking of external changes to HEAD MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of using FileSystemWatcher, emit repositoryChanged when refreshTopic is called. This reverts commit 2a8c48cb15d50b8686e5cb4f29a96f4431a0ec37. Fixes: QTCREATORBUG-21089 Change-Id: Iaee8a895f3bc087583cbdea11c6dc2c263694a86 Reviewed-by: André Hartmann Reviewed-by: Jarek Kobus --- src/plugins/git/branchmodel.cpp | 14 +--------- src/plugins/git/gitplugin.cpp | 47 +++++++++++++++++---------------- 2 files changed, 25 insertions(+), 36 deletions(-) diff --git a/src/plugins/git/branchmodel.cpp b/src/plugins/git/branchmodel.cpp index 4deefcb734c..2effa6f215e 100644 --- a/src/plugins/git/branchmodel.cpp +++ b/src/plugins/git/branchmodel.cpp @@ -11,7 +11,6 @@ #include #include -#include #include #include #include @@ -229,7 +228,6 @@ public: QString currentSha; QDateTime currentDateTime; QStringList obsoleteLocalBranches; - Utils::FileSystemWatcher fsWatcher; bool oldBranchesIncluded = false; struct OldEntry @@ -257,10 +255,6 @@ BranchModel::BranchModel(GitClient *client, QObject *parent) : // 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("Remote Branches"), "refs/remotes")); - connect(&d->fsWatcher, &Utils::FileSystemWatcher::fileChanged, this, [this] { - QString errorMessage; - refresh(d->workingDirectory, &errorMessage); - }); } BranchModel::~BranchModel() @@ -422,13 +416,7 @@ bool BranchModel::refresh(const FilePath &workingDirectory, QString *errorMessag return false; } - if (d->workingDirectory != workingDirectory) { - d->workingDirectory = workingDirectory; - d->fsWatcher.clear(); - const QString gitDir = d->client->findGitDirForRepository(workingDirectory); - if (!gitDir.isEmpty()) - d->fsWatcher.addFile(gitDir + "/HEAD", Utils::FileSystemWatcher::WatchModifiedDate); - } + d->workingDirectory = workingDirectory; const QStringList lines = output.split('\n'); for (const QString &l : lines) d->parseOutputLine(l); diff --git a/src/plugins/git/gitplugin.cpp b/src/plugins/git/gitplugin.cpp index a6bdfbf32e3..c77ce79bcdf 100644 --- a/src/plugins/git/gitplugin.cpp +++ b/src/plugins/git/gitplugin.cpp @@ -85,29 +85,6 @@ namespace Git::Internal { using GitClientMemberFunc = void (GitClient::*)(const FilePath &) const; -class GitTopicCache : public IVersionControl::TopicCache -{ -public: - GitTopicCache(GitClient *client) : - m_client(client) - { } - -protected: - FilePath trackFile(const FilePath &repository) override - { - const QString gitDir = m_client->findGitDirForRepository(repository); - return gitDir.isEmpty() ? FilePath() : FilePath::fromString(gitDir + "/HEAD"); - } - - QString refreshTopic(const FilePath &repository) override - { - return m_client->synchronousTopic(repository); - } - -private: - GitClient *m_client; -}; - class GitReflogEditorWidget : public GitEditorWidget { public: @@ -437,6 +414,30 @@ public: static GitPluginPrivate *dd = nullptr; +class GitTopicCache : public IVersionControl::TopicCache +{ +public: + GitTopicCache(GitClient *client) : + m_client(client) + { } + +protected: + FilePath trackFile(const FilePath &repository) override + { + const QString gitDir = m_client->findGitDirForRepository(repository); + return gitDir.isEmpty() ? FilePath() : FilePath::fromString(gitDir + "/HEAD"); + } + + QString refreshTopic(const FilePath &repository) override + { + emit dd->repositoryChanged(repository); + return m_client->synchronousTopic(repository); + } + +private: + GitClient *m_client; +}; + GitPluginPrivate::~GitPluginPrivate() { cleanCommitMessageFile();