mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-16 03:40:37 +08:00
Add get_diff tauri command
This commit is contained in:
Generated
+1
@@ -3880,6 +3880,7 @@ dependencies = [
|
||||
"nonempty",
|
||||
"radicle-git-ext",
|
||||
"radicle-std-ext",
|
||||
"serde",
|
||||
"tar",
|
||||
"thiserror",
|
||||
"url",
|
||||
|
||||
@@ -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"] }
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
pub mod auth;
|
||||
pub mod cob;
|
||||
pub mod diff;
|
||||
pub mod profile;
|
||||
pub mod repo;
|
||||
pub mod thread;
|
||||
|
||||
@@ -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<surf::diff::Diff, error::Error> {
|
||||
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)
|
||||
}
|
||||
@@ -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),
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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"]!;
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user