From e0d855267efdc8d88a39c1bc3cfdbb93a60ab676 Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Thu, 28 Mar 2024 14:32:34 +0100 Subject: [PATCH] [vcs-log-graph] compute correct start layout indexes for the branch heads Since branch heads are now being used as the start nodes for building graph layout, a head commit might be visited earlier from another head, giving it a layout index different from the currentLayoutIndex value. This commit avoids the problem altogether by computing layout indexes array for heads after all layout indexes have been calculated. follow-up: 1cd228ff6107d0ca03d5f3172f9940e0d55d9e4f GitOrigin-RevId: c01942bad60c09979711769905ac35a43b9c98f0 --- .../vcs/log/graph/impl/facade/SimpleGraphInfo.java | 7 +------ .../log/graph/impl/permanent/GraphLayoutBuilder.kt | 4 +--- .../vcs/log/graph/impl/permanent/GraphLayoutImpl.kt | 13 ++++++++++--- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/facade/SimpleGraphInfo.java b/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/facade/SimpleGraphInfo.java index 345c36eb8807..aaefd59e063a 100644 --- a/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/facade/SimpleGraphInfo.java +++ b/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/facade/SimpleGraphInfo.java @@ -92,12 +92,7 @@ public final class SimpleGraphInfo implements PermanentGraphInfo layoutIndexes[o])); - int[] starts = new int[headNodeIndexes.size()]; - for (int i = 0; i < starts.length; i++) { - starts[i] = layoutIndexes[headNodeIndexes.getInt(i)]; - } - - GraphLayoutImpl newLayout = new GraphLayoutImpl(layoutIndexes, headNodeIndexes, starts); + GraphLayoutImpl newLayout = new GraphLayoutImpl(layoutIndexes, headNodeIndexes); return new SimpleGraphInfo<>(newLinearGraph, newLayout, commitIdMapping, timestampGetter, LinearGraphUtils.convertIdsToNodeIndexes(linearGraph, branchNodeIds)); diff --git a/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/permanent/GraphLayoutBuilder.kt b/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/permanent/GraphLayoutBuilder.kt index 08a7e25afc20..4fd7c2125cae 100644 --- a/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/permanent/GraphLayoutBuilder.kt +++ b/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/permanent/GraphLayoutBuilder.kt @@ -25,13 +25,11 @@ object GraphLayoutBuilder { val sortedHeads = IntArrayList(allHeads).sortCatching(comparator) val layoutIndex = IntArray(graph.nodesCount()) - val startLayoutIndexForHead = IntArray(sortedHeads.size) var currentLayoutIndex = 1 for (i in sortedHeads.indices) { - startLayoutIndexForHead[i] = currentLayoutIndex currentLayoutIndex = dfs(graph, sortedHeads.getInt(i), currentLayoutIndex, layoutIndex) } - return GraphLayoutImpl(layoutIndex, sortedHeads, startLayoutIndexForHead) + return GraphLayoutImpl(layoutIndex, sortedHeads) } /** diff --git a/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/permanent/GraphLayoutImpl.kt b/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/permanent/GraphLayoutImpl.kt index 8f951eff1f16..ecdc47f10364 100644 --- a/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/permanent/GraphLayoutImpl.kt +++ b/platform/vcs-log/graph/src/com/intellij/vcs/log/graph/impl/permanent/GraphLayoutImpl.kt @@ -7,9 +7,8 @@ import it.unimi.dsi.fastutil.ints.IntList import java.util.* import kotlin.math.max -class GraphLayoutImpl(layoutIndex: IntArray, - private val headNodeIndex: IntList, - private val startLayoutIndexForHead: IntArray) : GraphLayout { +class GraphLayoutImpl(layoutIndex: IntArray, private val headNodeIndex: IntList) : GraphLayout { + private val startLayoutIndexForHead = getLayoutIndexesForHeads(layoutIndex, headNodeIndex) private val layoutIndex = CompressedIntList.newInstance(layoutIndex) override fun getLayoutIndex(nodeIndex: Int) = layoutIndex[nodeIndex] @@ -25,3 +24,11 @@ class GraphLayoutImpl(layoutIndex: IntArray, return if (i < 0) max(0, (-i - 2)) else i } } + +private fun getLayoutIndexesForHeads(layoutIndexes: IntArray, headNodeIndexes: IntList): IntArray { + val result = IntArray(headNodeIndexes.size) + for (i in result.indices) { + result[i] = layoutIndexes[headNodeIndexes.getInt(i)] + } + return result +}