From 4a6542abcd0179c313764caa232f47dc299605ea Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Thu, 28 Oct 2021 17:03:06 +0200 Subject: [PATCH] Fixed previous commits of uncommited changes not showing in the same column --- .../kotlin/app/git/graph/GraphCommitList.kt | 2 +- src/main/kotlin/app/git/graph/GraphNode.kt | 32 +++++++++++++------ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/app/git/graph/GraphCommitList.kt b/src/main/kotlin/app/git/graph/GraphCommitList.kt index a3d0907..c20b003 100644 --- a/src/main/kotlin/app/git/graph/GraphCommitList.kt +++ b/src/main/kotlin/app/git/graph/GraphCommitList.kt @@ -63,7 +63,7 @@ class GraphCommitList : RevCommitList() { override fun enter(index: Int, currCommit: GraphNode) { if(currCommit.id == parentId) { graphCommit.graphParent = currCommit - currCommit.addChild(graphCommit) + currCommit.addChild(graphCommit, addFirst = true) } setupChildren(currCommit) diff --git a/src/main/kotlin/app/git/graph/GraphNode.kt b/src/main/kotlin/app/git/graph/GraphNode.kt index 5400629..e6afca3 100644 --- a/src/main/kotlin/app/git/graph/GraphNode.kt +++ b/src/main/kotlin/app/git/graph/GraphNode.kt @@ -31,30 +31,42 @@ open class GraphNode(id: AnyObjectId?) : RevCommit(id), IGraphNode { mergingLanes = addLane(graphLane, mergingLanes) } - fun addChild(c: GraphNode) { + fun addChild(c: GraphNode, addFirst: Boolean = false) { when (val childrenCount = children.count()) { 0 -> children = arrayOf(c) - 1 -> if (!c.id.equals(children[0].id)) children = arrayOf(children[0], c) + 1 -> { + if (!c.id.equals(children[0].id)) { + children = if (addFirst) { + arrayOf(c, children[0]) + } else + arrayOf(children[0], c) + } + } else -> { for (pc in children) if (c.id.equals(pc.id)) return - val n: Array = children.copyOf(childrenCount + 1).run { - this[childrenCount] = c - requireNoNulls() + val resultArray = if (addFirst) { + val childList = mutableListOf(c) + childList.addAll(children) + childList.toTypedArray() + } else { + children.copyOf(childrenCount + 1).run { + this[childrenCount] = c + requireNoNulls() + } } - n[childrenCount] = c - children = n + children = resultArray } } } val childCount: Int - get() { - return children.size - } + get() { + return children.size + } /** * Get the nth child from this commit's child list.