Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix JGitCompletions memory leak #408

Merged
merged 1 commit into from Apr 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 20 additions & 11 deletions src/main/scala/scalafix/internal/sbt/JGitCompletions.scala
Expand Up @@ -18,32 +18,41 @@ class JGitCompletion(cwd: Path) {
RepositoryCache.FileKey
.isGitRepository(cwd.resolve(DOT_GIT).toFile, FS.DETECTED)

private val (refList, refs) =
val branchesAndTags: List[String] = {
if (isGitRepository) {
val builder = new FileRepositoryBuilder()
val repo = builder.readEnvironment().setWorkTree(cwd.toFile).build()
val refList0 =
val refList =
repo.getRefDatabase().getRefsByPrefix(RefDatabase.ALL).asScala
val git = new Git(repo)
val refs0 =
Try(git.log().setMaxCount(20).call().asScala.toList).getOrElse(Nil)
(refList0, refs0)
refList.map { ref => Repository.shortenRefName(ref.getName) }.toList
} else {
(Nil, Nil)
Nil
}

val branchesAndTags: List[String] =
refList.map { ref => Repository.shortenRefName(ref.getName) }.toList
}

private val dateFormatter = new GitDateFormatter(
GitDateFormatter.Format.RELATIVE
)
val last20Commits: List[(String, String)] =
val last20Commits: List[(String, String)] = {
val refs = {
if (isGitRepository) {
val builder = new FileRepositoryBuilder()
val repo = builder.readEnvironment().setWorkTree(cwd.toFile).build()
val git = new Git(repo)
val refs0 =
Try(git.log().setMaxCount(20).call().asScala.toList).getOrElse(Nil)
refs0
} else {
Nil
}
}

refs.map { ref =>
val relativeCommitTime =
dateFormatter.formatDate(refs.head.getCommitterIdent)
val abrev = ref.abbreviate(8).name
val short = ref.getShortMessage
(s"$abrev -- $short ($relativeCommitTime)", abrev)
}
}
}