Skip to content

Commit

Permalink
SLI-1786 Do no display a modal when computing branch information
Browse files Browse the repository at this point in the history
  • Loading branch information
nquinquenel committed Dec 27, 2024
1 parent 0626f6e commit 3548f7d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
8 changes: 1 addition & 7 deletions git/src/main/kotlin/org/sonarlint/intellij/git/GitRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,7 @@ class GitRepo(private val repo: GitRepository, private val project: Project) : V
}

private fun distance(project: Project, repository: GitRepository, from: String, to: String): Int? {
val mergeBase = try {
GitHistoryUtils.getMergeBase(project, repository.root, from, to) ?: return null
} catch (e: IllegalStateException) {
// SLI-1381: "There is no ProgressIndicator or Job in this thread" should simply be a loud error
SonarLintConsole.get(project).debug("Couldn't compute the git distance, reason: ${e.message}")
return null
}
val mergeBase = GitHistoryUtils.getMergeBase(project, repository.root, from, to) ?: return null
val aheadCount = getNumberOfCommitsBetween(repository, from, mergeBase.asString()) ?: return null
val behindCount = getNumberOfCommitsBetween(repository, to, mergeBase.asString()) ?: return null
return aheadCount + behindCount
Expand Down
22 changes: 21 additions & 1 deletion src/main/java/org/sonarlint/intellij/SonarLintIntelliJClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ import com.intellij.openapi.application.ModalityState
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.fileEditor.OpenFileDescriptor
import com.intellij.openapi.module.Module
import com.intellij.openapi.progress.PerformInBackgroundOption
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.progress.Task
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ProjectManager
import com.intellij.openapi.project.guessProjectDir
Expand All @@ -55,6 +59,7 @@ import java.security.cert.CertificateFactory
import java.security.cert.X509Certificate
import java.util.UUID
import java.util.concurrent.CancellationException
import java.util.concurrent.CompletableFuture
import org.apache.commons.text.StringEscapeUtils
import org.eclipse.lsp4j.jsonrpc.ResponseErrorException
import org.eclipse.lsp4j.jsonrpc.messages.ResponseError
Expand Down Expand Up @@ -628,7 +633,22 @@ object SonarLintIntelliJClient : SonarLintRpcClientDelegate {
}
} ?: return null
val repo = repositories.first()
return repo.electBestMatchingServerBranchForCurrentHead(mainBranchName, allBranchesNames) ?: mainBranchName

val project = BackendService.findModule(configurationScopeId)?.project
?: BackendService.findProject(configurationScopeId) ?: return null
val resultFuture = CompletableFuture<String>()
ProgressManager.getInstance().run(object : Task.Backgroundable(
project,
"Matching project branch…",
true,
PerformInBackgroundOption.ALWAYS_BACKGROUND
) {
override fun run(indicator: ProgressIndicator) {
val result = repo.electBestMatchingServerBranchForCurrentHead(mainBranchName, allBranchesNames) ?: mainBranchName
resultFuture.complete(result)
}
})
return computeOnPooledThread(project, "Waiting for branch matching result") { resultFuture.get() }
}

override fun matchProjectBranch(
Expand Down

0 comments on commit 3548f7d

Please sign in to comment.