[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
This commit is contained in:
Julia Beliaeva
2024-03-28 21:36:30 +00:00
committed by intellij-monorepo-bot
parent 00c776df24
commit e0d855267e
3 changed files with 12 additions and 12 deletions
@@ -92,12 +92,7 @@ public final class SimpleGraphInfo<CommitId> implements PermanentGraphInfo<Commi
}
ContainerUtil.sort(headNodeIndexes, Comparator.comparingInt(o -> 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));
@@ -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)
}
/**
@@ -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
}