From 21ce125931eb45198b0fe514c0f69735a0a23517 Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Sun, 26 Nov 2023 15:58:32 +0100 Subject: [PATCH] Added icon instead of used image on stash --- .../gitnuro/git/graph/GraphNode.kt | 1 + .../gitnuro/git/graph/GraphWalk.kt | 8 +- .../com/jetpackduba/gitnuro/ui/log/Log.kt | 93 +++++++++++-------- 3 files changed, 63 insertions(+), 39 deletions(-) diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/git/graph/GraphNode.kt b/src/main/kotlin/com/jetpackduba/gitnuro/git/graph/GraphNode.kt index 3bb4950..9ad79fc 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/git/graph/GraphNode.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/git/graph/GraphNode.kt @@ -16,6 +16,7 @@ open class GraphNode(id: AnyObjectId?) : RevCommit(id), IGraphNode { var lane: GraphLane = NO_LANE var children: Array = NO_CHILDREN var refs: List = NO_REFS + var isStash: Boolean = false fun addForkingOffLane(graphLane: GraphLane) { forkingOffLanes = addLane(graphLane, forkingOffLanes) diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/git/graph/GraphWalk.kt b/src/main/kotlin/com/jetpackduba/gitnuro/git/graph/GraphWalk.kt index fbd74d4..5bf7362 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/git/graph/GraphWalk.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/git/graph/GraphWalk.kt @@ -48,8 +48,12 @@ class GraphWalk(private var repository: Repository?) : RevWalk(repository) { override fun next(): RevCommit? { val graphNode = super.next() as GraphNode? - if (graphNode != null) - graphNode.refs = getRefs(graphNode) + if (graphNode != null) { + val refs = getRefs(graphNode) + + graphNode.isStash = refs.count() == 1 && refs.firstOrNull()?.name == "refs/stash" + graphNode.refs = refs + } return graphNode } diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/ui/log/Log.kt b/src/main/kotlin/com/jetpackduba/gitnuro/ui/log/Log.kt index bdd106f..6d42ad8 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/ui/log/Log.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/ui/log/Log.kt @@ -24,6 +24,7 @@ import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.geometry.Offset import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.graphics.drawscope.clipRect import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.input.key.onPreviewKeyEvent @@ -808,7 +809,6 @@ fun CommitLine( ) { CommitMessage( commit = graphNode, - refs = graphNode.refs, nodeColor = nodeColor, matchesSearchFilter = matchesSearchFilter, currentBranch = currentBranch, @@ -830,8 +830,7 @@ fun CommitLine( @Composable fun CommitMessage( - commit: RevCommit, - refs: List, + commit: GraphNode, currentBranch: Ref?, nodeColor: Color, matchesSearchFilter: Boolean?, @@ -852,35 +851,37 @@ fun CommitMessage( Row( modifier = Modifier.padding(start = 16.dp) ) { - refs.sortedWith { ref1, ref2 -> - if (ref1.isSameBranch(currentBranch)) { - -1 - } else { - ref1.name.compareTo(ref2.name) - } - }.forEach { ref -> - if (ref.isTag) { - TagChip( - ref = ref, - color = nodeColor, - onCheckoutTag = { onCheckoutRef(ref) }, - onDeleteTag = { onDeleteTag(ref) }, - ) - } else if (ref.isBranch) { - BranchChip( - ref = ref, - color = nodeColor, - currentBranch = currentBranch, - isCurrentBranch = ref.isSameBranch(currentBranch), - onCheckoutBranch = { onCheckoutRef(ref) }, - onMergeBranch = { onMergeBranch(ref) }, - onDeleteBranch = { onDeleteBranch(ref) }, - onDeleteRemoteBranch = { onDeleteRemoteBranch(ref) }, - onRebaseBranch = { onRebaseBranch(ref) }, - onPullRemoteBranch = { onPullRemoteBranch(ref) }, - onPushRemoteBranch = { onPushRemoteBranch(ref) }, - onChangeDefaultUpstreamBranch = { onChangeDefaultUpstreamBranch(ref) }, - ) + if (!commit.isStash) { + commit.refs.sortedWith { ref1, ref2 -> + if (ref1.isSameBranch(currentBranch)) { + -1 + } else { + ref1.name.compareTo(ref2.name) + } + }.forEach { ref -> + if (ref.isTag) { + TagChip( + ref = ref, + color = nodeColor, + onCheckoutTag = { onCheckoutRef(ref) }, + onDeleteTag = { onDeleteTag(ref) }, + ) + } else if (ref.isBranch) { + BranchChip( + ref = ref, + color = nodeColor, + currentBranch = currentBranch, + isCurrentBranch = ref.isSameBranch(currentBranch), + onCheckoutBranch = { onCheckoutRef(ref) }, + onMergeBranch = { onMergeBranch(ref) }, + onDeleteBranch = { onDeleteBranch(ref) }, + onDeleteRemoteBranch = { onDeleteRemoteBranch(ref) }, + onRebaseBranch = { onRebaseBranch(ref) }, + onPullRemoteBranch = { onPullRemoteBranch(ref) }, + onPushRemoteBranch = { onPushRemoteBranch(ref) }, + onChangeDefaultUpstreamBranch = { onChangeDefaultUpstreamBranch(ref) }, + ) + } } } } @@ -1028,19 +1029,37 @@ fun CommitNode( color: Color, ) { val author = plotCommit.authorIdent - Tooltip("${author.name} <${author.emailAddress}>") { + if (plotCommit.isStash) { Box( modifier = modifier .size(30.dp) .border(2.dp, color, shape = CircleShape) .clip(CircleShape) + .background(MaterialTheme.colors.background), + contentAlignment = Alignment.Center, ) { - AvatarImage( - modifier = Modifier.fillMaxSize(), - personIdent = plotCommit.authorIdent, - color = color, + Image( + painterResource(AppIcons.STASH), + modifier = Modifier.size(20.dp), + contentDescription = null, + colorFilter = ColorFilter.tint(color), ) } + } else { + Tooltip("${author.name} <${author.emailAddress}>") { + Box( + modifier = modifier + .size(30.dp) + .border(2.dp, color, shape = CircleShape) + .clip(CircleShape) + ) { + AvatarImage( + modifier = Modifier.fillMaxSize(), + personIdent = plotCommit.authorIdent, + color = color, + ) + } + } } }