mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[vcs-log-graph] transform functions to extension functions of the graph
This commit is contained in:
@@ -6,15 +6,15 @@ import com.intellij.vcs.log.graph.api.LinearGraph
|
||||
import com.intellij.vcs.log.graph.api.LiteLinearGraph
|
||||
import com.intellij.vcs.log.graph.utils.impl.BitSetFlags
|
||||
|
||||
fun getReachableNodes(graph: LinearGraph, headNodes: Set<Int>?): UnsignedBitSet {
|
||||
fun LinearGraph.getReachableNodes(headNodes: Set<Int>?): UnsignedBitSet {
|
||||
if (headNodes == null) {
|
||||
val nodesVisibility = UnsignedBitSet()
|
||||
nodesVisibility.set(0, graph.nodesCount() - 1, true)
|
||||
nodesVisibility.set(0, nodesCount() - 1, true)
|
||||
return nodesVisibility
|
||||
}
|
||||
|
||||
val result = UnsignedBitSet()
|
||||
DfsWalk(headNodes, graph).walk(true) { node: Int ->
|
||||
DfsWalk(headNodes, this).walk(true) { node: Int ->
|
||||
result.set(node, true)
|
||||
true
|
||||
}
|
||||
@@ -46,12 +46,12 @@ fun LiteLinearGraph.isAncestor(lowerNode: Int, upperNode: Int): Boolean {
|
||||
return result.get()
|
||||
}
|
||||
|
||||
fun getCorrespondingParent(graph: LiteLinearGraph, startNode: Int, endNode: Int, visited: Flags): Int {
|
||||
val candidates = graph.getNodes(startNode, LiteLinearGraph.NodeFilter.DOWN)
|
||||
fun LiteLinearGraph.getCorrespondingParent(startNode: Int, endNode: Int, visited: Flags): Int {
|
||||
val candidates = getNodes(startNode, LiteLinearGraph.NodeFilter.DOWN)
|
||||
if (candidates.size == 1) return candidates[0]
|
||||
if (candidates.contains(endNode)) return endNode
|
||||
|
||||
val bfsWalks = candidates.mapTo(mutableListOf()) { BfsWalk(it, graph, visited) }
|
||||
val bfsWalks = candidates.mapTo(mutableListOf()) { BfsWalk(it, this, visited) }
|
||||
|
||||
visited.setAll(false)
|
||||
do {
|
||||
|
||||
@@ -15,8 +15,7 @@ class BfsTests {
|
||||
|
||||
private fun assertCorrespondingParent(startNode: Int, endNode: Int, expectedParent: Int, graphBuilder: TestGraphBuilder.() -> Unit) {
|
||||
val graph = graph(graphBuilder)
|
||||
val actualParent = getCorrespondingParent(LinearGraphUtils.asLiteLinearGraph(graph), startNode, endNode,
|
||||
BitSetFlags(graph.nodesCount()))
|
||||
val actualParent = LinearGraphUtils.asLiteLinearGraph(graph).getCorrespondingParent(startNode, endNode, BitSetFlags(graph.nodesCount()))
|
||||
assertEquals(expectedParent, actualParent,
|
||||
"Incorrect parent found when walking from ${startNode} to ${endNode} in ${graph.asString(true)}")
|
||||
}
|
||||
|
||||
@@ -198,7 +198,7 @@ internal class FileHistoryRefiner(private val visibleLinearGraph: LinearGraph,
|
||||
namesData.getPathInParentRevision(previousCommit, permanentCommitsInfo.getCommitId(parentIndex), previousPath.filePath)
|
||||
}
|
||||
val path = findPathWithoutConflict(previousNodeId, pathGetter)
|
||||
path ?: pathGetter(getCorrespondingParent(permanentLinearGraph, previousNodeId, currentNodeId, visibilityBuffer))
|
||||
path ?: pathGetter(permanentLinearGraph.getCorrespondingParent(previousNodeId, currentNodeId, visibilityBuffer))
|
||||
}
|
||||
else {
|
||||
val pathGetter = { parentIndex: Int ->
|
||||
@@ -206,7 +206,7 @@ internal class FileHistoryRefiner(private val visibleLinearGraph: LinearGraph,
|
||||
}
|
||||
val path = findPathWithoutConflict(currentNodeId, pathGetter)
|
||||
// since in reality there is no edge between the nodes, but the whole path, we need to know, which parent is affected by this path
|
||||
path ?: pathGetter(getCorrespondingParent(permanentLinearGraph, currentNodeId, previousNodeId, visibilityBuffer))
|
||||
path ?: pathGetter(permanentLinearGraph.getCorrespondingParent(currentNodeId, previousNodeId, visibilityBuffer))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user