[vcs-log-graph] remove duplication in the code calculating visible nodes

GitOrigin-RevId: bbba9cb92504fe5b6dfdaa1404629c5d907857ea
This commit is contained in:
Julia Beliaeva
2024-04-03 01:35:25 +00:00
committed by intellij-monorepo-bot
parent 1813627e4b
commit 03d0986877
2 changed files with 25 additions and 24 deletions
@@ -4,10 +4,10 @@ package com.intellij.vcs.log.graph.impl.facade
import com.intellij.vcs.log.graph.api.elements.GraphElement
import com.intellij.vcs.log.graph.api.permanent.PermanentGraphInfo
import com.intellij.vcs.log.graph.collapsing.CollapsedGraph
import com.intellij.vcs.log.graph.collapsing.DottedFilterEdgesGenerator.Companion.update
import com.intellij.vcs.log.graph.utils.DfsWalk
import com.intellij.vcs.log.graph.collapsing.DottedFilterEdgesGenerator
import com.intellij.vcs.log.graph.utils.LinearGraphUtils
import com.intellij.vcs.log.graph.utils.UnsignedBitSet
import com.intellij.vcs.log.graph.utils.getReachableMatchingNodes
class FilteredController(delegateLinearGraphController: LinearGraphController,
permanentGraphInfo: PermanentGraphInfo<*>,
@@ -15,22 +15,12 @@ class FilteredController(delegateLinearGraphController: LinearGraphController,
visibleHeadsIds: Set<Int>? = null) :
CascadeController(delegateLinearGraphController, permanentGraphInfo) {
val collapsedGraph: CollapsedGraph
val collapsedGraph: CollapsedGraph = buildGraph(permanentGraphInfo.linearGraph.getReachableMatchingNodes(visibleHeadsIds, matchedIds))
init {
val initVisibility = UnsignedBitSet()
if (visibleHeadsIds != null) {
DfsWalk(visibleHeadsIds, permanentGraphInfo.linearGraph).walk(true) { node ->
if (matchedIds.contains(node)) initVisibility[node] = true
true
}
private fun buildGraph(visibility: UnsignedBitSet): CollapsedGraph {
return CollapsedGraph.newInstance(delegateController.compiledGraph, visibility).also {
DottedFilterEdgesGenerator.update(it, 0, it.delegatedGraph.nodesCount() - 1)
}
else {
for (matchedId in matchedIds) initVisibility[matchedId] = true
}
collapsedGraph = CollapsedGraph.newInstance(delegateLinearGraphController.compiledGraph, initVisibility)
update(collapsedGraph, 0, collapsedGraph.delegatedGraph.nodesCount() - 1)
}
override fun performLinearGraphAction(action: LinearGraphController.LinearGraphAction): LinearGraphController.LinearGraphAnswer {
@@ -1,4 +1,4 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.vcs.log.graph.utils
import com.intellij.openapi.util.Ref
@@ -14,18 +14,29 @@ import kotlin.math.max
* @return reachable nodes or all nodes if startNodes is null
*/
internal fun LinearGraph.getReachableNodes(startNodes: Set<Int>?): UnsignedBitSet {
return getReachableMatchingNodes(startNodes, null)
}
/**
* Get matching nodes reachable from the specified by down edges of the graph.
* @return reachable matching nodes or all matching nodes if startNodes is null
*/
internal fun LinearGraph.getReachableMatchingNodes(startNodes: Set<Int>?, matchedNodes: Set<Int>?): UnsignedBitSet {
val visibility = UnsignedBitSet()
if (startNodes == null) {
val nodesVisibility = UnsignedBitSet()
nodesVisibility.set(0, nodesCount() - 1, true)
return nodesVisibility
if (matchedNodes == null) {
visibility.set(0, nodesCount() - 1, true)
} else {
for (matchedId in matchedNodes) visibility[matchedId] = true
}
return visibility
}
val result = UnsignedBitSet()
DfsWalk(startNodes, this).walk(true) { node: Int ->
result.set(node, true)
DfsWalk(startNodes, this).walk(true) { node ->
if (matchedNodes == null || matchedNodes.contains(node)) visibility[node] = true
true
}
return result
return visibility
}
/**