Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -51,6 +52,7 @@ abstract class BaseGitActivity : ContinuationContainerActivity() {
PUSH,
RESET,
SYNC,
GC,
}

@Inject lateinit var gitSettings: GitSettings
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ class GitConfigActivity : BaseGitActivity() {
)
}
}
binding.gitGc.setOnClickListener {
lifecycleScope.launch {
launchGitOperation(GitOp.GC)
.fold(
success = ::finishOnSuccessHandler,
failure = { err -> promptOnErrorHandler(err) { finish() } },
)
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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))
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/layout/activity_git_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>