From b6c4fa0ed76fd7232da73fdfa16693e107bb83e4 Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Mon, 21 Feb 2022 15:14:31 +0100 Subject: [PATCH] Reduced number of operations that have to be executed to update the status --- src/main/kotlin/app/git/LogManager.kt | 8 +++----- src/main/kotlin/app/viewmodels/LogViewModel.kt | 18 ++++++++---------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/src/main/kotlin/app/git/LogManager.kt b/src/main/kotlin/app/git/LogManager.kt index 33c145b..5e1cfd5 100644 --- a/src/main/kotlin/app/git/LogManager.kt +++ b/src/main/kotlin/app/git/LogManager.kt @@ -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) diff --git a/src/main/kotlin/app/viewmodels/LogViewModel.kt b/src/main/kotlin/app/viewmodels/LogViewModel.kt index b220afc..39ee52c 100644 --- a/src/main/kotlin/app/viewmodels/LogViewModel.kt +++ b/src/main/kotlin/app/viewmodels/LogViewModel.kt @@ -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) }