Reduced number of operations that have to be executed to update the status

This commit is contained in:
Abdelilah El Aissaoui 2022-02-21 15:14:31 +01:00
parent 4ed10c0682
commit b6c4fa0ed7
2 changed files with 11 additions and 15 deletions

View File

@ -13,10 +13,8 @@ import org.eclipse.jgit.revwalk.RevCommit
import javax.inject.Inject
class LogManager @Inject constructor(
private val statusManager: StatusManager,
) {
suspend fun loadLog(git: Git, currentBranch: Ref?) = withContext(Dispatchers.IO) {
class LogManager @Inject constructor() {
suspend fun loadLog(git: Git, currentBranch: Ref?, hasUncommitedChanges: Boolean) = withContext(Dispatchers.IO) {
val commitList = GraphCommitList()
val repositoryState = git.repository.repositoryState
println("Repository state ${repositoryState.description}")
@ -30,7 +28,7 @@ class LogManager @Inject constructor(
walk.markStartAllRefs(Constants.R_REMOTES)
walk.markStartAllRefs(Constants.R_TAGS)
if (statusManager.hasUncommitedChanges(git))
if (hasUncommitedChanges)
commitList.addUncommitedChangesGraphCommit(logList.first())
commitList.source(walk)

View File

@ -29,17 +29,15 @@ class LogViewModel @Inject constructor(
_logStatus.value = LogStatus.Loading
val currentBranch = branchesManager.currentBranchRef(git)
val log = logManager.loadLog(git, currentBranch)
val hasUncommitedChanges = statusManager.hasUncommitedChanges(git)
val statsSummary = if (hasUncommitedChanges) {
statusManager.getStatusSummary(
git = git,
currentBranch = currentBranch,
repositoryState = repositoryManager.getRepositoryState(git),
)
} else
StatusSummary(0, 0, 0)
val statsSummary = statusManager.getStatusSummary(
git = git,
currentBranch = currentBranch,
repositoryState = repositoryManager.getRepositoryState(git),
)
val hasUncommitedChanges = statsSummary.addedCount + statsSummary.deletedCount + statsSummary.modifiedCount > 0
val log = logManager.loadLog(git, currentBranch, hasUncommitedChanges)
_logStatus.value = LogStatus.Loaded(hasUncommitedChanges, log, currentBranch, statsSummary)
}