diff options
Diffstat (limited to 'app/src/main/java/dev')
4 files changed, 44 insertions, 1 deletions
diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/git/base/BaseGitActivity.kt b/app/src/main/java/dev/msfjarvis/aps/ui/git/base/BaseGitActivity.kt index a008f6c7..e44e3e3c 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/git/base/BaseGitActivity.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/git/base/BaseGitActivity.kt @@ -19,6 +19,7 @@ import dev.msfjarvis.aps.util.extensions.sharedPrefs import dev.msfjarvis.aps.util.git.ErrorMessages import dev.msfjarvis.aps.util.git.operation.BreakOutOfDetached import dev.msfjarvis.aps.util.git.operation.CloneOperation +import dev.msfjarvis.aps.util.git.operation.GcOperation import dev.msfjarvis.aps.util.git.operation.PullOperation import dev.msfjarvis.aps.util.git.operation.PushOperation import dev.msfjarvis.aps.util.git.operation.ResetToRemoteOperation @@ -51,6 +52,7 @@ abstract class BaseGitActivity : ContinuationContainerActivity() { PUSH, RESET, SYNC, + GC, } @Inject lateinit var gitSettings: GitSettings @@ -77,8 +79,14 @@ abstract class BaseGitActivity : ContinuationContainerActivity() { GitOp.SYNC -> SyncOperation(this, gitSettings.rebaseOnPull) GitOp.BREAK_OUT_OF_DETACHED -> BreakOutOfDetached(this) GitOp.RESET -> ResetToRemoteOperation(this) + GitOp.GC -> GcOperation(this) } - return op.executeAfterAuthentication(gitSettings.authMode).mapError(::transformGitError) + return (if (op.requiresAuth) { + op.executeAfterAuthentication(gitSettings.authMode) + } else { + op.execute() + }) + .mapError(::transformGitError) } fun finishOnSuccessHandler(@Suppress("UNUSED_PARAMETER") nothing: Unit) { diff --git a/app/src/main/java/dev/msfjarvis/aps/ui/git/config/GitConfigActivity.kt b/app/src/main/java/dev/msfjarvis/aps/ui/git/config/GitConfigActivity.kt index 04014e17..4fed7b99 100644 --- a/app/src/main/java/dev/msfjarvis/aps/ui/git/config/GitConfigActivity.kt +++ b/app/src/main/java/dev/msfjarvis/aps/ui/git/config/GitConfigActivity.kt @@ -124,6 +124,15 @@ class GitConfigActivity : BaseGitActivity() { ) } } + binding.gitGc.setOnClickListener { + lifecycleScope.launch { + launchGitOperation(GitOp.GC) + .fold( + success = ::finishOnSuccessHandler, + failure = { err -> promptOnErrorHandler(err) { finish() } }, + ) + } + } } /** diff --git a/app/src/main/java/dev/msfjarvis/aps/util/git/operation/GcOperation.kt b/app/src/main/java/dev/msfjarvis/aps/util/git/operation/GcOperation.kt new file mode 100644 index 00000000..c070027e --- /dev/null +++ b/app/src/main/java/dev/msfjarvis/aps/util/git/operation/GcOperation.kt @@ -0,0 +1,22 @@ +/* + * Copyright © 2014-2022 The Android Password Store Authors. All Rights Reserved. + * SPDX-License-Identifier: GPL-3.0-only + */ + +package dev.msfjarvis.aps.util.git.operation + +import dev.msfjarvis.aps.util.git.sshj.ContinuationContainerActivity +import org.eclipse.jgit.api.GitCommand + +/** + * Run an aggressive garbage collection job on the repository, expiring every loose object to + * achieve the best compression. + */ +class GcOperation( + callingActivity: ContinuationContainerActivity, +) : GitOperation(callingActivity) { + + override val requiresAuth: Boolean = false + override val commands: Array<GitCommand<out Any>> = + arrayOf(git.gc().setAggressive(true).setExpire(null)) +} diff --git a/app/src/main/java/dev/msfjarvis/aps/util/git/operation/GitOperation.kt b/app/src/main/java/dev/msfjarvis/aps/util/git/operation/GitOperation.kt index 141de348..fe464069 100644 --- a/app/src/main/java/dev/msfjarvis/aps/util/git/operation/GitOperation.kt +++ b/app/src/main/java/dev/msfjarvis/aps/util/git/operation/GitOperation.kt @@ -57,7 +57,11 @@ import org.eclipse.jgit.transport.URIish */ abstract class GitOperation(protected val callingActivity: FragmentActivity) { + /** List of [GitCommand]s that are executed by an operation. */ abstract val commands: Array<GitCommand<out Any>> + + /** Whether the operation requires authentication or not. */ + open val requiresAuth: Boolean = true private val hostKeyFile = callingActivity.filesDir.resolve(".host_key") private var sshSessionFactory: SshjSessionFactory? = null private val hiltEntryPoint = |