From dd70101d7bf6b1a7708e6247171de24c4312f647 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Mon, 31 Jan 2022 12:02:37 +0200 Subject: [PATCH] Git: Block branch refresh for actions that open a new editor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refresh is called twice - first time when the editor is just opened, on this call the repository can be either empty, or the active project (even if the current file is from another repository). After the editor is initialized, setSource is called, and the state is recovered. But between these 2 calls, m_repository is empty, and synchronous actions are still executed (and fail). Fixes: QTCREATORBUG-26952 Change-Id: I1767b35f0e9f24da2c447d0b565b410742c560d9 Reviewed-by: André Hartmann Reviewed-by: Robert Löhning Reviewed-by: hjk --- src/plugins/git/branchview.cpp | 30 ++++++++++++++++++++++++------ src/plugins/git/branchview.h | 1 + 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/plugins/git/branchview.cpp b/src/plugins/git/branchview.cpp index ffc346d71ca..eed65d20aa5 100644 --- a/src/plugins/git/branchview.cpp +++ b/src/plugins/git/branchview.cpp @@ -76,6 +76,18 @@ protected: } }; +struct SetInContext +{ + SetInContext(bool &block) : m_block(block) + { + m_origValue = m_block; + m_block = true; + } + ~SetInContext() { m_block = m_origValue; } + bool &m_block; + bool m_origValue; +}; + BranchView::BranchView() : m_includeOldEntriesAction(new QAction(tr("Include Old Entries"), this)) , m_includeTagsAction(new QAction(tr("Include Tags"), this)) @@ -148,7 +160,7 @@ void BranchView::refreshIfSame(const FilePath &repository) void BranchView::refresh(const FilePath &repository, bool force) { - if (m_repository == repository && !force) + if (m_blockRefresh || (m_repository == repository && !force)) return; m_repository = repository; @@ -261,8 +273,10 @@ void BranchView::slotCustomContextMenu(const QPoint &point) contextMenu.addSeparator(); contextMenu.addAction(tr("&Diff"), this, [this] { const QString fullName = m_model->fullName(selectedIndex(), true); - if (!fullName.isEmpty()) + if (!fullName.isEmpty()) { + SetInContext block(m_blockRefresh); GitClient::instance()->diffBranch(m_repository, fullName); + } }); contextMenu.addAction(tr("&Log"), this, [this] { log(selectedIndex()); }); contextMenu.addAction(tr("Reflo&g"), this, [this] { reflog(selectedIndex()); }); @@ -582,15 +596,19 @@ bool BranchView::cherryPick() void BranchView::log(const QModelIndex &idx) { const QString branchName = m_model->fullName(idx, true); - if (!branchName.isEmpty()) - GitClient::instance()->log(m_repository, QString(), false, {branchName}); + if (branchName.isEmpty()) + return; + SetInContext block(m_blockRefresh); + GitClient::instance()->log(m_repository, QString(), false, {branchName}); } void BranchView::reflog(const QModelIndex &idx) { const QString branchName = m_model->fullName(idx, true); - if (!branchName.isEmpty()) - GitClient::instance()->reflog(m_repository, branchName); + if (branchName.isEmpty()) + return; + SetInContext block(m_blockRefresh); + GitClient::instance()->reflog(m_repository, branchName); } void BranchView::push() diff --git a/src/plugins/git/branchview.h b/src/plugins/git/branchview.h index 9d46f52e6e1..a11379f8e6e 100644 --- a/src/plugins/git/branchview.h +++ b/src/plugins/git/branchview.h @@ -97,6 +97,7 @@ private: BranchModel *m_model = nullptr; BranchFilterModel *m_filterModel = nullptr; Utils::FilePath m_repository; + bool m_blockRefresh = false; }; class BranchViewFactory : public Core::INavigationWidgetFactory