diff --git a/Cargo.lock b/Cargo.lock index a9d4b62bb..98d402e89 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3880,6 +3880,7 @@ dependencies = [ "nonempty", "radicle-git-ext", "radicle-std-ext", + "serde", "tar", "thiserror", "url", diff --git a/crates/radicle-tauri/Cargo.toml b/crates/radicle-tauri/Cargo.toml index af386ef48..d37ab004f 100644 --- a/crates/radicle-tauri/Cargo.toml +++ b/crates/radicle-tauri/Cargo.toml @@ -19,7 +19,7 @@ anyhow = { version = "1.0" } base64 = { version = "0.22" } log = { version = "0.4" } radicle = { git = "https://seed.radicle.xyz/z3gqcJUoA1n9HaHKufZs5FCSGazv5.git" } -radicle-surf = { version = "0.22.0" } +radicle-surf = { version = "0.22.0", features = ["serde"] } serde = { version = "1.0", features = ["derive"] } serde_json = { version = "1.0" } tauri = { version = "2.0", features = ["isolation"] } diff --git a/crates/radicle-tauri/src/commands.rs b/crates/radicle-tauri/src/commands.rs index 44faa3d95..12c3bfd65 100644 --- a/crates/radicle-tauri/src/commands.rs +++ b/crates/radicle-tauri/src/commands.rs @@ -1,5 +1,6 @@ pub mod auth; pub mod cob; +pub mod diff; pub mod profile; pub mod repo; pub mod thread; diff --git a/crates/radicle-tauri/src/commands/diff.rs b/crates/radicle-tauri/src/commands/diff.rs new file mode 100644 index 000000000..207f04b6f --- /dev/null +++ b/crates/radicle-tauri/src/commands/diff.rs @@ -0,0 +1,45 @@ +use radicle::storage::ReadStorage; +use radicle_surf as surf; + +use radicle::git; +use radicle::identity; +use serde::Deserialize; +use serde::Serialize; + +use crate::{error, AppState}; + +#[derive(Serialize, Deserialize)] +pub struct Options { + pub base: git::Oid, + pub head: git::Oid, + pub unified: u32, +} + +#[tauri::command] +pub async fn get_diff( + ctx: tauri::State<'_, AppState>, + rid: identity::RepoId, + options: Options, +) -> Result { + let repo = ctx.profile.storage.repository(rid)?.backend; + let base = repo.find_commit(*options.base)?; + let head = repo.find_commit(*options.head)?; + + let mut opts = git::raw::DiffOptions::new(); + opts.patience(true) + .minimal(true) + .context_lines(options.unified); + + let mut find_opts = git::raw::DiffFindOptions::new(); + find_opts.exact_match_only(true); + find_opts.all(true); + + let left = base.tree()?; + let right = head.tree()?; + + let mut diff = repo.diff_tree_to_tree(Some(&left), Some(&right), Some(&mut opts))?; + diff.find_similar(Some(&mut find_opts))?; + let diff = surf::diff::Diff::try_from(diff)?; + + Ok::<_, error::Error>(diff) +} diff --git a/crates/radicle-tauri/src/error.rs b/crates/radicle-tauri/src/error.rs index ca7c2fe60..f77f7b5b9 100644 --- a/crates/radicle-tauri/src/error.rs +++ b/crates/radicle-tauri/src/error.rs @@ -50,6 +50,10 @@ pub enum Error { #[error(transparent)] Git2(#[from] radicle::git::raw::Error), + /// Diff error. + #[error(transparent)] + Diff(#[from] radicle_surf::diff::git::error::Diff), + /// Storage refs error. #[error(transparent)] StorageRef(#[from] radicle::storage::refs::Error), diff --git a/crates/radicle-tauri/src/lib.rs b/crates/radicle-tauri/src/lib.rs index 277dc154c..0c21312be 100644 --- a/crates/radicle-tauri/src/lib.rs +++ b/crates/radicle-tauri/src/lib.rs @@ -8,7 +8,7 @@ use tauri::Manager; use radicle::node::Handle; use radicle::Node; -use commands::{auth, cob, profile, repo, thread}; +use commands::{auth, cob, diff, profile, repo, thread}; struct AppState { profile: radicle::Profile, @@ -76,6 +76,7 @@ pub fn run() { repo::list_repos, repo::repo_by_id, repo::diff_stats, + diff::get_diff, cob::get_file_by_oid, cob::activity_by_id, cob::save_embed, diff --git a/src/views/repo/Patch.svelte b/src/views/repo/Patch.svelte index 2c835c66b..986cdc92f 100644 --- a/src/views/repo/Patch.svelte +++ b/src/views/repo/Patch.svelte @@ -10,6 +10,7 @@ formatTimestamp, patchStatusColor, } from "@app/lib/utils"; + import { invoke } from "@tauri-apps/api/core"; import Border from "@app/components/Border.svelte"; import CopyableId from "@app/components/CopyableId.svelte"; @@ -26,6 +27,15 @@ export let revisions: Revision[]; export let config: Config; + $: void invoke("get_diff", { + rid: repo.rid, + options: { + base: revisions[0].base, + head: revisions[0].head, + unified: 10, + }, + }).then(console.log); + $: project = repo.payloads["xyz.radicle.project"]!;