diff --git a/git/src/main/kotlin/org/sonarlint/intellij/git/GitRepo.kt b/git/src/main/kotlin/org/sonarlint/intellij/git/GitRepo.kt index 9fe7acd5b..1fa9c8640 100644 --- a/git/src/main/kotlin/org/sonarlint/intellij/git/GitRepo.kt +++ b/git/src/main/kotlin/org/sonarlint/intellij/git/GitRepo.kt @@ -19,9 +19,7 @@ */ package org.sonarlint.intellij.git -import com.intellij.openapi.progress.ProgressManager import com.intellij.openapi.project.Project -import git4idea.GitRevisionNumber import git4idea.commands.Git import git4idea.commands.GitCommand import git4idea.commands.GitLineHandler @@ -76,14 +74,15 @@ class GitRepo(private val repo: GitRepository, private val project: Project) : V } private fun distance(project: Project, repository: GitRepository, from: String, to: String): Int? { - val revisionNumber = ProgressManager.getInstance().runProcessWithProgressSynchronously<GitRevisionNumber, Exception>( - { GitHistoryUtils.getMergeBase(project, repository.root, from, to) }, - "SonarQube: Computing branch information", - true, - repository.project - ) - val aheadCount = getNumberOfCommitsBetween(repository, from, revisionNumber.asString()) ?: return null - val behindCount = getNumberOfCommitsBetween(repository, to, revisionNumber.asString()) ?: return null + 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 aheadCount = getNumberOfCommitsBetween(repository, from, mergeBase.asString()) ?: return null + val behindCount = getNumberOfCommitsBetween(repository, to, mergeBase.asString()) ?: return null return aheadCount + behindCount } @@ -92,20 +91,13 @@ class GitRepo(private val repo: GitRepository, private val project: Project) : V from: String, to: String, ): Int? { - return ProgressManager.getInstance().runProcessWithProgressSynchronously<Int?, Exception>( - { - val handler = GitLineHandler(repository.project, repository.root, GitCommand.REV_LIST) - handler.addParameters("--count", "$from..$to") - handler.setSilent(true) - try { - Integer.parseInt(Git.getInstance().runCommand(handler).getOutputOrThrow().trim()) - } catch (e: Exception) { - throw Exception("Cannot get number of commits between '$from' and '$to'", e) - } - }, - "SonarQube: Computing branch information", - true, - repository.project - ) + val handler = GitLineHandler(repository.project, repository.root, GitCommand.REV_LIST) + handler.addParameters("--count", "$from..$to") + handler.setSilent(true) + return try { + Integer.parseInt(Git.getInstance().runCommand(handler).getOutputOrThrow().trim()) + } catch (e: Exception) { + throw Exception("Cannot get number of commits between '$from' and '$to'", e) + } } } diff --git a/src/main/java/org/sonarlint/intellij/SonarLintIntelliJClient.kt b/src/main/java/org/sonarlint/intellij/SonarLintIntelliJClient.kt index e6c7112b4..0fe41070b 100644 --- a/src/main/java/org/sonarlint/intellij/SonarLintIntelliJClient.kt +++ b/src/main/java/org/sonarlint/intellij/SonarLintIntelliJClient.kt @@ -628,9 +628,7 @@ object SonarLintIntelliJClient : SonarLintRpcClientDelegate { } } ?: return null val repo = repositories.first() - return computeOnPooledThread("Electing best matching branch") { - repo.electBestMatchingServerBranchForCurrentHead(mainBranchName, allBranchesNames) ?: mainBranchName - } + return repo.electBestMatchingServerBranchForCurrentHead(mainBranchName, allBranchesNames) ?: mainBranchName } override fun matchProjectBranch( @@ -745,7 +743,7 @@ object SonarLintIntelliJClient : SonarLintRpcClientDelegate { filesInContentRoots.addAll(it.listFiles(module)) } - val forcedLanguages = collectContributedLanguages(module, filesInContentRoots).toMap() + val forcedLanguages = collectContributedLanguages(module, filesInContentRoots) val clientFiles = filesInContentRoots.mapNotNull { file -> val forcedLanguage = forcedLanguages[file]?.let { fl -> Language.valueOf(fl.name) }