[vcs]: Renaming and formatting IJPL-246741

GitOrigin-RevId: 492c68d47b86068da82f1ba17629afe12969db44
This commit is contained in:
Jakub Dolezal
2026-07-29 14:49:35 +00:00
committed by intellij-monorepo-bot
parent c26964d1dd
commit 5226804512
7 changed files with 47 additions and 32 deletions
@@ -13,7 +13,7 @@ import org.jetbrains.concurrency.Promise
interface GitBranchesPopup: TreePopup {
val userResized: Boolean
var groupByPrefix: Boolean
var groupByDirectory: Boolean
fun restoreDefaultSize()
@@ -136,10 +136,10 @@ abstract class GitBranchesPopupBase<T : GitBranchesPopupStepBase>(
final override var userResized: Boolean
private set
final override var groupByPrefix: Boolean
get() = treeStep.treeModel.isPrefixGrouping
final override var groupByDirectory: Boolean
get() = treeStep.treeModel.isDirectoryGrouping
set(value) {
treeStep.treeModel.isPrefixGrouping = value
treeStep.treeModel.isDirectoryGrouping = value
}
private val expandedPaths = HashSet<TreePath>()
@@ -109,8 +109,8 @@ abstract class GitBranchesPopupStepBase(
}
is GitBranchesTreeModel.BranchesPrefixGroup -> value.prefix.last()
is GitBranchesTreeModel.RefTypeUnderRepository -> value.type.getText()
is RefUnderRepository -> getRefText(value.ref, treeModel.isPrefixGrouping)
is GitReference -> getRefText(value, treeModel.isPrefixGrouping)
is RefUnderRepository -> getRefText(value.ref, treeModel.isDirectoryGrouping)
is GitReference -> getRefText(value, treeModel.isDirectoryGrouping)
is PopupFactoryImpl.ActionItem -> value.text
is GitBranchesTreeModel.PresentableNode -> value.presentableText
else -> null
@@ -39,7 +39,7 @@ abstract class GitBranchesTreeModel(
protected var nameMatcher: MinusculeMatcher? = null
private set
var isPrefixGrouping: Boolean by observable(GitVcsSettings.getInstance(project).branchSettings.isGroupingEnabled(GROUPING_BY_DIRECTORY)) { _, oldValue, newValue ->
var isDirectoryGrouping: Boolean by observable(GitVcsSettings.getInstance(project).branchSettings.isGroupingEnabled(GROUPING_BY_DIRECTORY)) { _, oldValue, newValue ->
if (oldValue != newValue) {
applyFilterAndRebuild(null)
}
@@ -63,13 +63,18 @@ abstract class GitBranchesTreeModel(
val recentBranches = getRecentBranches()
actionsTree = LazyActionsHolder(project, actions, matcher)
localBranchesTree = LazyRefsSubtreeHolder(
localBranches,
matcher,
::isPrefixGrouping,
{ recentBranches?.contains(it) ?: false },
refComparatorGetter = ::getRefComparator
unsortedRefs = localBranches,
matcher = matcher,
isDirectoryGrouping = ::isDirectoryGrouping,
exceptRefFilter = { recentBranches?.contains(it) ?: false },
refComparatorGetter = ::getRefComparator,
)
remoteBranchesTree = LazyRefsSubtreeHolder(
unsortedRefs = remoteBranches,
matcher = matcher,
isDirectoryGrouping = ::isDirectoryGrouping,
refComparatorGetter = ::getRefComparator,
)
remoteBranchesTree = LazyRefsSubtreeHolder(remoteBranches, matcher, ::isPrefixGrouping, refComparatorGetter = ::getRefComparator)
rebuildTags(matcher)
}
@@ -119,9 +124,17 @@ abstract class GitBranchesTreeModel(
private fun rebuildTags(matcher: MinusculeMatcher?) {
tagsTree =
if (GitVcsSettings.getInstance(project).showTags())
LazyRefsSubtreeHolder(getTags(), matcher, ::isPrefixGrouping, refComparatorGetter = ::getRefComparator)
else LazyRefsSubtreeHolder.emptyHolder()
if (GitVcsSettings.getInstance(project).showTags()) {
LazyRefsSubtreeHolder(
unsortedRefs = getTags(),
matcher = matcher,
isDirectoryGrouping = ::isDirectoryGrouping,
refComparatorGetter = ::getRefComparator,
)
}
else {
LazyRefsSubtreeHolder.emptyHolder()
}
}
protected fun getRefComparator(affectedRepositories: List<GitRepositoryModel> = repositories): Comparator<GitReference> {
@@ -130,7 +143,7 @@ abstract class GitBranchesTreeModel(
} then compareBy {
!it.isFavoriteInAll(affectedRepositories)
} then compareBy {
!(isPrefixGrouping && it.name.contains('/'))
!(isDirectoryGrouping && it.name.contains('/'))
} then compareBy(GitReference.REFS_NAMES_COMPARATOR) { it.name }
}
@@ -89,7 +89,7 @@ fun createTreePathFor(model: GitBranchesTreeModel, value: Any): TreePath? {
add(refType)
}
}
val nameParts = if (model.isPrefixGrouping) reference.name.split('/') else listOf(reference.name)
val nameParts = if (model.isDirectoryGrouping) reference.name.split('/') else listOf(reference.name)
val currentPrefix = mutableListOf<String>()
for (prefixPart in nameParts.init()) {
currentPrefix.add(prefixPart)
@@ -238,7 +238,7 @@ open class LazyHolder<N>(nodes: List<N>,
class LazyRefsSubtreeHolder<out T : GitReference>(
unsortedRefs: Collection<T>,
matcher: MinusculeMatcher?,
isPrefixGrouping: () -> Boolean,
isDirectoryGrouping: () -> Boolean,
exceptRefFilter: (T) -> Boolean = { false },
refComparatorGetter: () -> Comparator<GitReference>,
) {
@@ -255,7 +255,7 @@ class LazyRefsSubtreeHolder<out T : GitReference>(
val tree: Map<String, Any> by lazy {
val infoList = matchingResult.matchedNodes
TelemetryManager.getInstance().getTracer(VcsScope).spanBuilder(GitBranchesPopupSpan.BuildingTree.getName()).use { span ->
buildSubTree(infoList.map { (if (isPrefixGrouping()) it.name.split('/') else listOf(it.name)) to it })
buildSubTree(infoList.map { (if (isDirectoryGrouping()) it.name.split('/') else listOf(it.name)) to it })
}
}
@@ -152,24 +152,24 @@ internal class GitBranchesTreeMultiRepoFilteringModel(
private inner class LazyRepositoryBranchesSubtreeHolder(private val repository: GitRepositoryModel) {
val localBranches by lazy {
LazyRefsSubtreeHolder(
repository.state.localBranchesOrCurrent,
nameMatcher,
::isPrefixGrouping,
unsortedRefs = repository.state.localBranchesOrCurrent,
matcher = nameMatcher,
isDirectoryGrouping = ::isDirectoryGrouping,
refComparatorGetter = { getRefComparator(listOf(repository)) })
}
val remoteBranches by lazy {
LazyRefsSubtreeHolder(
repository.state.remoteBranches,
nameMatcher,
::isPrefixGrouping,
unsortedRefs = repository.state.remoteBranches,
matcher = nameMatcher,
isDirectoryGrouping = ::isDirectoryGrouping,
refComparatorGetter = { getRefComparator(listOf(repository)) })
}
val tags by lazy {
LazyRefsSubtreeHolder(
repository.state.tags,
nameMatcher,
::isPrefixGrouping,
unsortedRefs = repository.state.tags,
matcher = nameMatcher,
isDirectoryGrouping = ::isDirectoryGrouping,
refComparatorGetter = { getRefComparator(listOf(repository)) })
}
}
@@ -25,9 +25,11 @@ open class GitBranchesTreeSingleRepoModel(
override fun rebuild(matcher: MinusculeMatcher?) {
super.rebuild(matcher)
val recentCheckoutBranches = getRecentBranches()
recentCheckoutBranchesTree = LazyRefsSubtreeHolder(recentCheckoutBranches, matcher,
::isPrefixGrouping,
refComparatorGetter = ::emptyBranchComparator)
recentCheckoutBranchesTree = LazyRefsSubtreeHolder(
unsortedRefs = recentCheckoutBranches, matcher = matcher,
isDirectoryGrouping = ::isDirectoryGrouping,
refComparatorGetter = ::emptyBranchComparator,
)
}
override fun getLocalBranches(): Collection<GitStandardLocalBranch> = repository.state.localBranchesOrCurrent