From 853c7d92a7bd7545df2b099ea6f8a58aa12e6ab1 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Mon, 24 Jun 2019 11:34:19 +0100 Subject: [PATCH] git: don't wait for the log refresh to show the Update Project notification if custom filters are not set For simplicity, consider only the Path filter: it will be moved to the Settings in one of next commits, and will be the only preserved filter. If there is no Paths filter, we don't need the up-to-date VisiblePack to show the notification. Therefore collect only the necessary information (available at once from Git), and show the notification. If user presses the "View Commits" link fast, he'll have to wait until the log is refreshed and filtered. If there is a Path filter, then we'll have to wait, because the number of commits matching the filter is unavailable until the VisiblePack is ready. Partial fix of IDEA-216137. GitOrigin-RevId: d55d22d2faecf5c844fcced7c2639d3f1ed101aa --- .../src/git4idea/update/GitUpdateInfoAsLog.kt | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/plugins/git4idea/src/git4idea/update/GitUpdateInfoAsLog.kt b/plugins/git4idea/src/git4idea/update/GitUpdateInfoAsLog.kt index 41d585610790..7e1e2de8b232 100644 --- a/plugins/git4idea/src/git4idea/update/GitUpdateInfoAsLog.kt +++ b/plugins/git4idea/src/git4idea/update/GitUpdateInfoAsLog.kt @@ -53,21 +53,34 @@ class GitUpdateInfoAsLog(private val project: Project, fun buildAndShowNotification() { notificationShown = false VcsLogContentUtil.runWhenLogIsReady(project) { log, logManager -> - val listener = object : DataPackChangeListener { - override fun onDataPackChange(dataPack: DataPack) { - showNotificationIfRangesAreReachable(log, dataPack, logManager, this) - } + if (!isPathFilterSet()) { // if no preserved filters are set, we don't need the log to show the notification + showTabAndNotificationAfterCalculations(logManager) + } + else { + waitForLogRefreshAndShowNotification(log, logManager) } - - log.dataManager?.addDataPackChangeListener(listener) - - GuiUtils.invokeLaterIfNeeded({ - // the log may be refreshed before we subscribe to the listener - showNotificationIfRangesAreReachable(log, logManager.dataManager.dataPack, logManager, listener) - }, ModalityState.defaultModalityState()) } } + private fun waitForLogRefreshAndShowNotification(log: VcsProjectLog, logManager: VcsLogManager) { + val listener = object : DataPackChangeListener { + override fun onDataPackChange(dataPack: DataPack) { + showNotificationIfRangesAreReachable(log, dataPack, logManager, this) + } + } + + log.dataManager?.addDataPackChangeListener(listener) + + GuiUtils.invokeLaterIfNeeded({ + // the log may be refreshed before we subscribe to the listener + showNotificationIfRangesAreReachable(log, logManager.dataManager.dataPack, logManager, listener) + }, ModalityState.defaultModalityState()) + } + + private fun isPathFilterSet() : Boolean { + return project.service().getFilterValues(STRUCTURE_FILTER.name) != null + } + @CalledInAwt private fun showNotificationIfRangesAreReachable(log: VcsProjectLog, dataPack: DataPack, @@ -120,7 +133,7 @@ class GitUpdateInfoAsLog(private val project: Project, // null for initial filters means that filters will be loaded from properties: saved filters + the range filter which we've just set val logUi = VcsLogUiImpl(logId, logData, logManager.colorManager, properties, refresher, null) - val listener = MyVisiblePackChangeListener(logUi, updatedFilesCount, updateCommitsCount, properties.havePresetFilters()) + val listener = MyVisiblePackChangeListener(logUi, updatedFilesCount, updateCommitsCount, isPathFilterSet()) refresher.addVisiblePackChangeListener(listener) return logUi } @@ -141,11 +154,6 @@ class GitUpdateInfoAsLog(private val project: Project, mainProperties.saveFilterValues(filterName, values) } } - - fun havePresetFilters(): Boolean { - val filters = mainProperties.state.FILTERS - return if (filters[RANGE_FILTER.name] != null) filters.size > 1 else filters.isNotEmpty() - } } private fun calcUpdatedCommitsCount(): Int {