Graph now shows properly the HEAD commits when rebasing & commits referenced by unpeeled tags

This commit is contained in:
Abdelilah El Aissaoui 2022-04-02 04:00:53 +02:00
parent 457d604575
commit 59a36fed08
3 changed files with 25 additions and 8 deletions

View File

@ -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)

View File

@ -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
}

View File

@ -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(