git: use GitBranch for branches dashboard nodes

GitOrigin-RevId: e6c9b25783aa05d4aea6a8e48cf32a4d84809218
This commit is contained in:
Aleksey Pivovarov
2024-01-11 16:59:15 +01:00
committed by intellij-monorepo-bot
parent 06232bde44
commit d5746cfcbd
2 changed files with 16 additions and 14 deletions

View File

@@ -9,6 +9,7 @@ import com.intellij.vcs.log.impl.VcsProjectLog
import com.intellij.vcs.log.util.exclusiveCommits
import com.intellij.vcs.log.util.findBranch
import com.intellij.vcs.log.visible.filters.VcsLogFilterObject
import git4idea.GitBranch
import git4idea.branch.GitBranchIncomingOutgoingManager
import git4idea.branch.GitBranchType
import git4idea.repo.GitRepository
@@ -19,23 +20,23 @@ import it.unimi.dsi.fastutil.ints.IntSet
internal object BranchesDashboardUtil {
fun getLocalBranches(project: Project, rootsToFilter: Set<VirtualFile>?): Set<BranchInfo> {
val localMap = mutableMapOf<String, MutableSet<GitRepository>>()
val localMap = mutableMapOf<GitBranch, MutableSet<GitRepository>>()
for (repo in GitRepositoryManager.getInstance(project).repositories) {
if (rootsToFilter != null && !rootsToFilter.contains(repo.root)) continue
for (branch in repo.branches.localBranches) {
localMap.computeIfAbsent(branch.name) { hashSetOf() }.add(repo)
localMap.computeIfAbsent(branch) { hashSetOf() }.add(repo)
}
val currentBranch = repo.currentBranch
if (currentBranch != null) {
localMap.computeIfAbsent(currentBranch.name) { hashSetOf() }.add(repo)
localMap.computeIfAbsent(currentBranch) { hashSetOf() }.add(repo)
}
}
val gitBranchManager = project.service<GitBranchManager>()
val local = localMap.map { (branchName, repos) ->
BranchInfo(branchName, true, repos.any { it.currentBranch?.name == branchName },
repos.any { gitBranchManager.isFavorite(GitBranchType.LOCAL, it, branchName) },
repos.anyIncomingOutgoingState(branchName),
val local = localMap.map { (branch, repos) ->
BranchInfo(branch, true, repos.any { it.currentBranch == branch },
repos.any { gitBranchManager.isFavorite(GitBranchType.LOCAL, it, branch.name) },
repos.anyIncomingOutgoingState(branch.name),
repos.toList())
}.toHashSet()
@@ -43,18 +44,18 @@ internal object BranchesDashboardUtil {
}
fun getRemoteBranches(project: Project, rootsToFilter: Set<VirtualFile>?): Set<BranchInfo> {
val remoteMap = mutableMapOf<String, MutableList<GitRepository>>()
val remoteMap = mutableMapOf<GitBranch, MutableList<GitRepository>>()
for (repo in GitRepositoryManager.getInstance(project).repositories) {
if (rootsToFilter != null && !rootsToFilter.contains(repo.root)) continue
for (remoteBranch in repo.branches.remoteBranches) {
remoteMap.computeIfAbsent(remoteBranch.name) { mutableListOf() }.add(repo)
remoteMap.computeIfAbsent(remoteBranch) { mutableListOf() }.add(repo)
}
}
val gitBranchManager = project.service<GitBranchManager>()
return remoteMap.map { (branchName, repos) ->
BranchInfo(branchName, false, false,
repos.any { gitBranchManager.isFavorite(GitBranchType.REMOTE, it, branchName) },
return remoteMap.map { (branch, repos) ->
BranchInfo(branch, false, false,
repos.any { gitBranchManager.isFavorite(GitBranchType.REMOTE, it, branch.name) },
null,
repos)
}.toHashSet()

View File

@@ -6,10 +6,10 @@ import com.intellij.dvcs.branch.GroupingKey
import com.intellij.dvcs.branch.GroupingKey.GROUPING_BY_DIRECTORY
import com.intellij.dvcs.branch.GroupingKey.GROUPING_BY_REPOSITORY
import com.intellij.dvcs.ui.BranchActionGroup
import com.intellij.openapi.actionSystem.DataKey
import com.intellij.openapi.components.service
import com.intellij.openapi.util.NlsSafe
import com.intellij.util.ThreeState
import git4idea.GitBranch
import git4idea.branch.GitBranchType
import git4idea.i18n.GitBundle.message
import git4idea.repo.GitRepository
@@ -23,13 +23,14 @@ import javax.swing.tree.DefaultMutableTreeNode
internal data class RemoteInfo(val remoteName: String, val repository: GitRepository?)
internal data class BranchInfo(val branchName: @NlsSafe String,
internal data class BranchInfo(val branch: GitBranch,
val isLocal: Boolean,
val isCurrent: Boolean,
var isFavorite: Boolean,
var incomingOutgoingState: IncomingOutgoing? = null,
val repositories: List<GitRepository>) {
var isMy: ThreeState = ThreeState.UNSURE
val branchName: @NlsSafe String get() = branch.name
override fun toString() = branchName
}