aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/dev/msfjarvis/aps/ui/git/base/BaseGitActivity.kt10
-rw-r--r--app/src/main/java/dev/msfjarvis/aps/ui/git/config/GitConfigActivity.kt9
-rw-r--r--app/src/main/java/dev/msfjarvis/aps/util/git/operation/GcOperation.kt22
-rw-r--r--app/src/main/java/dev/msfjarvis/aps/util/git/operation/GitOperation.kt4
-rw-r--r--app/src/main/res/layout/activity_git_config.xml8
-rw-r--r--app/src/main/res/values/strings.xml1
6 files changed, 53 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 =
diff --git a/app/src/main/res/layout/activity_git_config.xml b/app/src/main/res/layout/activity_git_config.xml
index d0479b09..364c5287 100644
--- a/app/src/main/res/layout/activity_git_config.xml
+++ b/app/src/main/res/layout/activity_git_config.xml
@@ -102,4 +102,12 @@
android:text="@string/reset_to_remote"
app:layout_constraintTop_toBottomOf="@id/git_abort_rebase" />
+ <com.google.android.material.button.MaterialButton
+ android:id="@+id/git_gc"
+ android:layout_marginTop="8dp"
+ android:text="@string/git_run_gc_job"
+ app:layout_constraintTop_toBottomOf="@id/git_reset_to_remote"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" />
+
</androidx.constraintlayout.widget.ConstraintLayout>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index c11e6f25..88484947 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -392,5 +392,6 @@
<string name="pgp_key_import_succeeded_message">The key ID of the imported key is given below, please review it for correctness:\n%1$s</string>
<string name="pref_category_pgp_title">PGP settings</string>
<string name="pwgen_some_error_occurred">Some error occurred</string>
+ <string name="git_run_gc_job">Run garbage collection job</string>
</resources>