diff --git a/src/main/kotlin/app/git/FileChangesWatcher.kt b/src/main/kotlin/app/git/FileChangesWatcher.kt index 4a6c575..e4a79d8 100644 --- a/src/main/kotlin/app/git/FileChangesWatcher.kt +++ b/src/main/kotlin/app/git/FileChangesWatcher.kt @@ -1,6 +1,7 @@ package app.git import app.extensions.systemSeparator +import app.logging.printLog import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.SharedFlow @@ -13,6 +14,8 @@ import java.nio.file.StandardWatchEventKinds.* import java.nio.file.attribute.BasicFileAttributes import javax.inject.Inject +private const val TAG = "FileChangesWatcher" + class FileChangesWatcher @Inject constructor() { private val _changesNotifier = MutableSharedFlow() @@ -61,11 +64,13 @@ class FileChangesWatcher @Inject constructor() { val fullPathOfFileChanged = "$pathStr$systemSeparator.git$systemSeparator$fileChanged" // Ignore COMMIT_EDITMSG changes - if(isGitMessageFile(pathStr, fullPathOfFileChanged)) + if(isGitMessageFile(pathStr, fullPathOfFileChanged)) { + printLog(TAG, "Ignored changes in $fullPathOfFileChanged") return@withContext + } } - println("Has git dir changed: $hasGitDirectoryChanged") + printLog(TAG, "Has git dir changed: $hasGitDirectoryChanged") _changesNotifier.emit(hasGitDirectoryChanged) @@ -78,7 +83,7 @@ class FileChangesWatcher @Inject constructor() { if (eventFile.isDirectory) { val eventPath = eventFile.toPath() - println("New directory $eventFile detected, adding it to watchService") + printLog(TAG, "New directory $eventFile detected, adding it to watchService") val watchKey = eventPath.register(watchService, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY) keys[watchKey] = eventPath diff --git a/src/main/kotlin/app/git/LogManager.kt b/src/main/kotlin/app/git/LogManager.kt index 0078852..7835829 100644 --- a/src/main/kotlin/app/git/LogManager.kt +++ b/src/main/kotlin/app/git/LogManager.kt @@ -2,6 +2,7 @@ package app.git import app.git.graph.GraphCommitList import app.git.graph.GraphWalk +import app.logging.printLog import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ensureActive import kotlinx.coroutines.withContext @@ -12,12 +13,15 @@ import org.eclipse.jgit.lib.Ref import org.eclipse.jgit.revwalk.RevCommit import javax.inject.Inject +private const val TAG = "LogManager" class LogManager @Inject constructor() { suspend fun loadLog(git: Git, currentBranch: Ref?, hasUncommitedChanges: Boolean, commitsLimit: Int) = withContext(Dispatchers.IO) { val commitList = GraphCommitList() val repositoryState = git.repository.repositoryState - println("Repository state ${repositoryState.description}") + + printLog(TAG, "Repository state ${repositoryState.description}") + if (currentBranch != null || repositoryState.isRebasing) { // Current branch is null when there is no log (new repo) or rebasing val logList = git.log().setMaxCount(1).call().toList() diff --git a/src/main/kotlin/app/logging/logger.kt b/src/main/kotlin/app/logging/logger.kt new file mode 100644 index 0000000..c4c1791 --- /dev/null +++ b/src/main/kotlin/app/logging/logger.kt @@ -0,0 +1,5 @@ +package app.logging + +fun printLog(tag: String, message: String) { + println("$tag - $message") +} \ No newline at end of file diff --git a/src/main/kotlin/app/viewmodels/TabViewModel.kt b/src/main/kotlin/app/viewmodels/TabViewModel.kt index 53d4cde..c92571b 100644 --- a/src/main/kotlin/app/viewmodels/TabViewModel.kt +++ b/src/main/kotlin/app/viewmodels/TabViewModel.kt @@ -5,6 +5,7 @@ import app.ErrorsManager import app.credentials.CredentialsState import app.credentials.CredentialsStateManager import app.git.* +import app.logging.printLog import app.newErrorNow import app.ui.SelectedItem import app.updates.Update @@ -24,6 +25,8 @@ import javax.inject.Provider private const val MIN_TIME_IN_MS_BETWEEN_REFRESHES = 1000L +private const val TAG = "TabViewModel" + /** * Contains all the information related to a tab and its subcomponents (smaller composables like the log, branches, * commit changes, etc.). It holds a reference to every view model because this class lives as long as the tab is open (survives @@ -93,7 +96,7 @@ class TabViewModel @Inject constructor( launch { tabState.refreshData.collect { refreshType -> when (refreshType) { - RefreshType.NONE -> println("Not refreshing...") + RefreshType.NONE -> printLog(TAG, "Not refreshing...") RefreshType.ALL_DATA -> refreshRepositoryInfo() RefreshType.REPO_STATE -> refreshRepositoryState() RefreshType.ONLY_LOG -> refreshLog() @@ -148,7 +151,7 @@ class TabViewModel @Inject constructor( } fun openRepository(directory: File) = tabState.safeProcessingWihoutGit { - println("Trying to open repository ${directory.absoluteFile}") + printLog(TAG, "Trying to open repository ${directory.absoluteFile}") _repositorySelectionStatus.value = RepositorySelectionStatus.Opening(directory.absolutePath) @@ -174,7 +177,7 @@ class TabViewModel @Inject constructor( private suspend fun loadRepositoryState(git: Git) = withContext(Dispatchers.IO) { val newRepoState = repositoryManager.getRepositoryState(git) - println("Refreshing repository state $newRepoState") + printLog(TAG, "Refreshing repository state $newRepoState") _repositoryState.value = newRepoState onRepositoryStateChanged(newRepoState) @@ -196,7 +199,7 @@ class TabViewModel @Inject constructor( launch { fileChangesWatcher.changesNotifier.collect { latestUpdateChangedGitDir -> if (!tabState.operationRunning) { // Only update if there isn't any process running - println("Detected changes in the repository's directory") + printLog(TAG, "Detected changes in the repository's directory") if (latestUpdateChangedGitDir) { hasGitDirChanged = true @@ -214,11 +217,11 @@ class TabViewModel @Inject constructor( // operation may be running if (diffTime > MIN_TIME_IN_MS_BETWEEN_REFRESHES && !hasGitDirChanged) { updateApp(false) - println("Sync emit with diff time $diffTime") + printLog(TAG, "Sync emit with diff time $diffTime") } else { asyncJob = async { delay(MIN_TIME_IN_MS_BETWEEN_REFRESHES) - println("Async emit") + printLog(TAG, "Async emit") if (isActive) updateApp(hasGitDirChanged) @@ -228,7 +231,7 @@ class TabViewModel @Inject constructor( lastNotify = currentTimeMillis } else { - println("Ignoring changed occurred during operation running...") + printLog(TAG, "Ignoring changed occurred during operation running...") } } } @@ -240,11 +243,11 @@ class TabViewModel @Inject constructor( suspend fun updateApp(hasGitDirChanged: Boolean) { if (hasGitDirChanged) { - println("Changes detected in git directory, full refresh") + printLog(TAG, "Changes detected in git directory, full refresh") refreshRepositoryInfo() } else { - println("Changes detected, partial refresh") + printLog(TAG, "Changes detected, partial refresh") checkUncommitedChanges() } @@ -255,7 +258,7 @@ class TabViewModel @Inject constructor( ) { git -> val uncommitedChangesStateChanged = statusViewModel.updateHasUncommitedChanges(git) - println("Has uncommitedChangesStateChanged $uncommitedChangesStateChanged") + printLog(TAG, "Has uncommitedChangesStateChanged $uncommitedChangesStateChanged") // Update the log only if the uncommitedChanges status has changed or requested if (uncommitedChangesStateChanged || fullUpdateLog) @@ -303,7 +306,7 @@ class TabViewModel @Inject constructor( private fun updateDiffEntry() { val diffSelected = diffSelected.value - println("Update diff entry $diffSelected") + printLog(TAG, "Update diff entry $diffSelected") if (diffSelected != null) { diffViewModel.updateDiff(diffSelected)