mirror of
https://seed.radicle.dev/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git
synced 2026-11-16 08:10:40 +08:00
Implement caching for the `Issue` and `Patch` COB. This is achieved by having the `Transaction::initial` and `Transaction::commit` methods take a cache which can update the newly created/updated object. The `Store::remove` method also takes the cache for removing the object from the cache, as well as the repository. This meant that the `*Mut` types for the respective COBs are required to carry a cache alongside the repository store. Identities will not be cached, and so this is always set to `NoCache` -- which performs no caching, and always succeeds. To perform cache reading for issues and patches, the `cache::Issues` and `cache::Patches` traits are introduced. They capture the minimal amount of methods that are needed for the `rad issue` and `rad patch` CLI commands. The implementor for each of these traits is there respective `Cache` types, which combines their backing repository store and the SQLite database. They both provide convenience methods: - `create` (and `draft` for patches) - `get_mut` - `remove` which can be used instead of their repository store counterparts. All uses of the repository stores (where needed) are replaced with `Cache` types. Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com> X-Clacks-Overhead: GNU Terry Pratchett
51 lines
1.5 KiB
Rust
51 lines
1.5 KiB
Rust
use radicle::cob::patch;
|
|
use radicle::git;
|
|
use radicle::prelude::*;
|
|
use radicle::storage::git::Repository;
|
|
|
|
use crate::terminal as term;
|
|
use crate::terminal::patch::*;
|
|
|
|
/// Run patch update.
|
|
pub fn run(
|
|
patch_id: patch::PatchId,
|
|
base_id: Option<git::raw::Oid>,
|
|
message: term::patch::Message,
|
|
profile: &Profile,
|
|
repository: &Repository,
|
|
workdir: &git::raw::Repository,
|
|
) -> anyhow::Result<()> {
|
|
// `HEAD`; This is what we are proposing as a patch.
|
|
let head_branch = try_branch(workdir.head()?)?;
|
|
|
|
let (_, target_oid) = get_merge_target(repository, &head_branch)?;
|
|
let mut patches = profile.patches_mut(repository)?;
|
|
let Ok(mut patch) = patches.get_mut(&patch_id) else {
|
|
anyhow::bail!("Patch `{patch_id}` not found");
|
|
};
|
|
|
|
let head_oid = branch_oid(&head_branch)?;
|
|
let base_oid = match base_id {
|
|
Some(oid) => oid,
|
|
None => repository.backend.merge_base(*target_oid, *head_oid)?,
|
|
};
|
|
|
|
// N.b. we don't update if both the head and base are the same as
|
|
// any previous revision
|
|
if patch
|
|
.revisions()
|
|
.any(|(_, revision)| revision.head() == head_oid && **revision.base() == base_oid)
|
|
{
|
|
return Ok(());
|
|
}
|
|
|
|
let (_, revision) = patch.latest();
|
|
let message = term::patch::get_update_message(message, workdir, revision, &head_oid)?;
|
|
let signer = term::signer(profile)?;
|
|
let revision = patch.update(message, base_oid, *head_oid, &signer)?;
|
|
|
|
term::print(revision);
|
|
|
|
Ok(())
|
|
}
|