Greatly improved performance of "stage all" in huge workspaces.
This specially noticable in repositories that contain binary blobs or huge files count. Fixes #129
This commit is contained in:
parent
c67d25bb17
commit
f53c306099
1 changed files with 37 additions and 9 deletions
|
@ -5,17 +5,45 @@ import kotlinx.coroutines.withContext
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class StageAllUseCase @Inject constructor() {
|
|
||||||
|
class StageAllUseCase @Inject constructor(
|
||||||
|
private val getStatusUseCase: GetStatusUseCase,
|
||||||
|
private val getUnstagedUseCase: GetUnstagedUseCase,
|
||||||
|
) {
|
||||||
suspend operator fun invoke(git: Git): Unit = withContext(Dispatchers.IO) {
|
suspend operator fun invoke(git: Git): Unit = withContext(Dispatchers.IO) {
|
||||||
git
|
val status = getStatusUseCase(git)
|
||||||
|
val unstaged = getUnstagedUseCase(status)
|
||||||
|
|
||||||
|
addAllExceptNew(git, unstaged.filter { it.statusType != StatusType.ADDED })
|
||||||
|
addNewFiles(git, unstaged.filter { it.statusType == StatusType.ADDED })
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The setUpdate flag of the addCommand adds deleted files but not newly added when active
|
||||||
|
*/
|
||||||
|
private fun addAllExceptNew(git: Git, allExceptNew: List<StatusEntry>) {
|
||||||
|
val addCommand = git
|
||||||
.add()
|
.add()
|
||||||
.addFilepattern(".")
|
|
||||||
.setUpdate(true) // Modified and deleted files
|
for (entry in allExceptNew) {
|
||||||
.call()
|
addCommand.addFilepattern(entry.filePath)
|
||||||
git
|
}
|
||||||
|
|
||||||
|
addCommand.setUpdate(true)
|
||||||
|
|
||||||
|
addCommand.call()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun addNewFiles(git: Git, newFiles: List<StatusEntry>) {
|
||||||
|
val addCommand = git
|
||||||
.add()
|
.add()
|
||||||
.addFilepattern(".")
|
|
||||||
.setUpdate(false) // For newly added files
|
for (path in newFiles) {
|
||||||
.call()
|
addCommand.addFilepattern(path.filePath)
|
||||||
|
}
|
||||||
|
|
||||||
|
addCommand.setUpdate(false)
|
||||||
|
|
||||||
|
addCommand.call()
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue