From 59a36fed0872c90c2fa71c2db9e2e1447039e1fb Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Sat, 2 Apr 2022 04:00:53 +0200 Subject: [PATCH] Graph now shows properly the HEAD commits when rebasing & commits referenced by unpeeled tags --- src/main/kotlin/app/git/LogManager.kt | 4 ++++ src/main/kotlin/app/git/graph/GraphWalk.kt | 12 +++++++++--- src/main/kotlin/app/ui/log/Log.kt | 17 ++++++++++++----- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/app/git/LogManager.kt b/src/main/kotlin/app/git/LogManager.kt index 5e1cfd5..a6be07d 100644 --- a/src/main/kotlin/app/git/LogManager.kt +++ b/src/main/kotlin/app/git/LogManager.kt @@ -24,6 +24,10 @@ class LogManager @Inject constructor() { val walk = GraphWalk(git.repository) walk.use { + // Without this, during rebase conflicts the graph won't show the HEAD commits (new commits created + // by the rebase) + walk.markStart(walk.lookupCommit(logList.first())) + walk.markStartAllRefs(Constants.R_HEADS) walk.markStartAllRefs(Constants.R_REMOTES) walk.markStartAllRefs(Constants.R_TAGS) diff --git a/src/main/kotlin/app/git/graph/GraphWalk.kt b/src/main/kotlin/app/git/graph/GraphWalk.kt index 81fb0ed..cf4dc6c 100644 --- a/src/main/kotlin/app/git/graph/GraphWalk.kt +++ b/src/main/kotlin/app/git/graph/GraphWalk.kt @@ -111,10 +111,16 @@ class GraphWalk(private var repository: Repository?) : RevWalk(repository) { private fun markStartRef(ref: Ref) { try { - val refTarget: Any = parseAny(ref.leaf.objectId) + val refTarget = parseAny(ref.leaf.objectId) - if (refTarget is RevCommit) - markStart(refTarget) + when (refTarget) { + is RevCommit -> markStart(refTarget) + // RevTag case handles commits without branches but only tags. + is RevTag -> { + val commit = lookupCommit(refTarget.`object`) + markStart(commit) + } + } } catch (e: MissingObjectException) { // Ignore missing Refs } diff --git a/src/main/kotlin/app/ui/log/Log.kt b/src/main/kotlin/app/ui/log/Log.kt index 65743bb..160c16e 100644 --- a/src/main/kotlin/app/ui/log/Log.kt +++ b/src/main/kotlin/app/ui/log/Log.kt @@ -54,7 +54,6 @@ import app.viewmodels.LogStatus import app.viewmodels.LogViewModel import kotlinx.coroutines.flow.collect import kotlinx.coroutines.launch -import openDirectoryDialog import org.eclipse.jgit.lib.Ref import org.eclipse.jgit.lib.RepositoryState import org.eclipse.jgit.revwalk.RevCommit @@ -69,7 +68,13 @@ private val colors = listOf( ) private const val CANVAS_MIN_WIDTH = 100 -private const val MIN_GRAPH_LINES = 2 +private const val MIN_GRAPH_LANES = 2 + +/** + * Additional number of lanes to simulate to create a margin at the end of the graph. + */ +private const val MARGIN_GRAPH_LANES = 2 +private const val LANE_WIDTH = 30f private const val DIVIDER_WIDTH = 8 // TODO Min size for message column @@ -355,10 +360,12 @@ fun GraphList( hasUncommitedChanges: Boolean, ) { val graphRealWidth = remember(commitList, graphWidth) { - val maxLinePosition = if (commitList.isNotEmpty()) commitList.maxOf { it.lane.position } - else MIN_GRAPH_LINES + val maxLinePosition = if (commitList.isNotEmpty()) + commitList.maxOf { it.lane.position } + else + MIN_GRAPH_LANES - ((maxLinePosition + 2) * 30f).dp + ((maxLinePosition + MARGIN_GRAPH_LANES) * LANE_WIDTH).dp } Box(