Add the ability to run garbage collection on the internal Git repository (#1683)
This commit is contained in:
parent
e7fbcd4f85
commit
6c7a066ea6
7 changed files with 54 additions and 1 deletions
|
@ -15,6 +15,7 @@ All notable changes to this project will be documented in this file.
|
|||
- Another workaround for SteamGuard's non-standard OTP format
|
||||
- Allow importing QR code from images
|
||||
- Introduce a new opt-in PGP backend powered by [PGPainless](https://github.com/pgpainless/pgpainless) that does not require OpenKeychain
|
||||
- Add the ability to run garbage collection on the internal Git repository
|
||||
|
||||
### Fixed
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -124,6 +124,15 @@ class GitConfigActivity : BaseGitActivity() {
|
|||
)
|
||||
}
|
||||
}
|
||||
binding.gitGc.setOnClickListener {
|
||||
lifecycleScope.launch {
|
||||
launchGitOperation(GitOp.GC)
|
||||
.fold(
|
||||
success = ::finishOnSuccessHandler,
|
||||
failure = { err -> promptOnErrorHandler(err) { finish() } },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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))
|
||||
}
|
|
@ -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 =
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue