Skip to content

Commit

Permalink
Revert "SLI-1734 Use ProgressIndicator to compute git information (#1261
Browse files Browse the repository at this point in the history
)"

This reverts commit 002171a.
  • Loading branch information
eray-felek-sonarsource committed Dec 19, 2024
1 parent a6bf5be commit afd98c6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 29 deletions.
42 changes: 17 additions & 25 deletions git/src/main/kotlin/org/sonarlint/intellij/git/GitRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand All @@ -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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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) }
Expand Down

0 comments on commit afd98c6

Please sign in to comment.