From eba37c01faeaf2e533327a5d48f2d55dc1fa517c Mon Sep 17 00:00:00 2001 From: Lorenz Leutgeb Date: Sat, 21 Mar 2026 11:21:40 +0100 Subject: [PATCH] radicle-types: Fix OID conversion The `radicle` crate switched its OID `struct`. The new `struct` does not convert to/from the OID `struct` in `radicle-surf`. Introduce an ad-hoc conversion. --- crates/radicle-types/src/diff.rs | 2 +- crates/radicle-types/src/lib.rs | 1 + crates/radicle-types/src/oid.rs | 7 +++++++ crates/radicle-types/src/repo.rs | 8 ++++++-- crates/radicle-types/src/source/blob.rs | 2 +- crates/radicle-types/src/source/commit.rs | 8 ++++++-- crates/radicle-types/src/source/tree.rs | 8 ++++---- crates/radicle-types/src/syntax.rs | 18 +++++++++--------- crates/radicle-types/src/traits/repo.rs | 14 ++++++++------ 9 files changed, 43 insertions(+), 25 deletions(-) create mode 100644 crates/radicle-types/src/oid.rs diff --git a/crates/radicle-types/src/diff.rs b/crates/radicle-types/src/diff.rs index e2d2686e1..d1860ef8d 100644 --- a/crates/radicle-types/src/diff.rs +++ b/crates/radicle-types/src/diff.rs @@ -152,7 +152,7 @@ pub struct DiffFile { impl From for DiffFile { fn from(value: surf::diff::DiffFile) -> Self { Self { - oid: value.oid, + oid: crate::oid::from_surf(value.oid), mode: value.mode.into(), } } diff --git a/crates/radicle-types/src/lib.rs b/crates/radicle-types/src/lib.rs index 40185f8f2..a8f6f5613 100644 --- a/crates/radicle-types/src/lib.rs +++ b/crates/radicle-types/src/lib.rs @@ -11,6 +11,7 @@ pub mod config; pub mod diff; pub mod domain; pub mod error; +pub mod oid; pub mod outbound; pub mod repo; pub mod source; diff --git a/crates/radicle-types/src/oid.rs b/crates/radicle-types/src/oid.rs new file mode 100644 index 000000000..b856e6a1f --- /dev/null +++ b/crates/radicle-types/src/oid.rs @@ -0,0 +1,7 @@ +pub(crate) fn from_surf(oid: radicle_surf::Oid) -> radicle::git::Oid { + radicle::git::Oid::from(radicle::git::raw::Oid::from(oid)) +} + +pub(crate) fn into_surf(oid: radicle::git::Oid) -> radicle_surf::Oid { + radicle_surf::Oid::from(radicle::git::raw::Oid::from(oid)) +} diff --git a/crates/radicle-types/src/repo.rs b/crates/radicle-types/src/repo.rs index 4360a6dff..551404ebe 100644 --- a/crates/radicle-types/src/repo.rs +++ b/crates/radicle-types/src/repo.rs @@ -172,12 +172,16 @@ pub struct Commit { impl From for Commit { fn from(value: surf::Commit) -> Self { Self { - id: value.id, + id: crate::oid::from_surf(value.id), author: value.author, committer: value.committer, message: value.message, summary: value.summary, - parents: value.parents, + parents: value + .parents + .into_iter() + .map(crate::oid::from_surf) + .collect(), } } } diff --git a/crates/radicle-types/src/source/blob.rs b/crates/radicle-types/src/source/blob.rs index 62a5a3dab..378ef9ce2 100644 --- a/crates/radicle-types/src/source/blob.rs +++ b/crates/radicle-types/src/source/blob.rs @@ -35,7 +35,7 @@ impl> From> for Blob { let mime_type = infer::get(blob.content()).map(|i| i.mime_type().to_string()); Blob { - id: blob.object_id(), + id: crate::oid::from_surf(blob.object_id()), binary: blob.is_binary(), commit: blob.commit().clone().into(), content, diff --git a/crates/radicle-types/src/source/commit.rs b/crates/radicle-types/src/source/commit.rs index 7a4fdfaed..4dbeae9a9 100644 --- a/crates/radicle-types/src/source/commit.rs +++ b/crates/radicle-types/src/source/commit.rs @@ -23,12 +23,16 @@ pub struct Commit { impl From for Commit { fn from(commit: surf::Commit) -> Self { Commit { - id: commit.id, + id: crate::oid::from_surf(commit.id), author: commit.author, committer: commit.committer, message: commit.message.to_string(), summary: commit.summary.to_string(), - parents: commit.parents.into_iter().collect::>(), + parents: commit + .parents + .into_iter() + .map(crate::oid::from_surf) + .collect::>(), } } } diff --git a/crates/radicle-types/src/source/tree.rs b/crates/radicle-types/src/source/tree.rs index aa69d8a1a..99ff36f98 100644 --- a/crates/radicle-types/src/source/tree.rs +++ b/crates/radicle-types/src/source/tree.rs @@ -21,7 +21,7 @@ pub struct Tree { impl Tree { pub fn from_surf(tree: surf::tree::Tree, path: &std::path::Path) -> Self { Tree { - id: tree.object_id(), + id: crate::oid::from_surf(tree.object_id()), path: path.to_path_buf(), entries: tree .entries() @@ -76,9 +76,9 @@ impl Entry { impl Entry { pub fn object_id(&self) -> Oid { match self.kind { - surf::tree::EntryKind::Blob(id) => id, - surf::tree::EntryKind::Tree(id) => id, - surf::tree::EntryKind::Submodule { id, .. } => id, + surf::tree::EntryKind::Blob(id) => crate::oid::from_surf(id), + surf::tree::EntryKind::Tree(id) => crate::oid::from_surf(id), + surf::tree::EntryKind::Submodule { id, .. } => crate::oid::from_surf(id), } } } diff --git a/crates/radicle-types/src/syntax.rs b/crates/radicle-types/src/syntax.rs index c80025e23..9bb081a0b 100644 --- a/crates/radicle-types/src/syntax.rs +++ b/crates/radicle-types/src/syntax.rs @@ -531,7 +531,7 @@ pub trait Repo { impl Repo for git::raw::Repository { fn blob(&self, oid: git::Oid) -> Result { - let blob = self.find_blob(*oid)?; + let blob = self.find_blob(oid.into())?; if blob.is_binary() { Ok(Blob::Binary) @@ -721,8 +721,8 @@ impl ToPretty for surf::diff::Moved { type Context = (); fn pretty(&self, hi: &mut Highlighter, _: &Self::Context, repo: &R) -> Self::Output { - let old = Some((self.old_path.as_path(), self.old.oid)); - let new = Some((self.new_path.as_path(), self.new.oid)); + let old = Some((self.old_path.as_path(), crate::oid::from_surf(self.old.oid))); + let new = Some((self.new_path.as_path(), crate::oid::from_surf(self.new.oid))); let blobs = Blobs::from_paths(old, new, repo); types::diff::Moved { @@ -741,7 +741,7 @@ impl ToPretty for surf::diff::Added { fn pretty(&self, hi: &mut Highlighter, _: &Self::Context, repo: &R) -> Self::Output { let old = None; - let new = Some((self.path.as_path(), self.new.oid)); + let new = Some((self.path.as_path(), crate::oid::from_surf(self.new.oid))); let blobs = Blobs::from_paths(old, new, repo); types::diff::Added { @@ -757,7 +757,7 @@ impl ToPretty for surf::diff::Deleted { type Context = (); fn pretty(&self, hi: &mut Highlighter, _: &Self::Context, repo: &R) -> Self::Output { - let old = Some((self.path.as_path(), self.old.oid)); + let old = Some((self.path.as_path(), crate::oid::from_surf(self.old.oid))); let new = None; let blobs = Blobs::from_paths(old, new, repo); @@ -774,8 +774,8 @@ impl ToPretty for surf::diff::Modified { type Context = (); fn pretty(&self, hi: &mut Highlighter, _: &Self::Context, repo: &R) -> Self::Output { - let old = Some((self.path.as_path(), self.old.oid)); - let new = Some((self.path.as_path(), self.new.oid)); + let old = Some((self.path.as_path(), crate::oid::from_surf(self.old.oid))); + let new = Some((self.path.as_path(), crate::oid::from_surf(self.new.oid))); let blobs = Blobs::from_paths(old, new, repo); types::diff::Modified { @@ -792,8 +792,8 @@ impl ToPretty for surf::diff::Copied { type Context = (); fn pretty(&self, hi: &mut Highlighter, _: &Self::Context, repo: &R) -> Self::Output { - let old = Some((self.old_path.as_path(), self.old.oid)); - let new = Some((self.new_path.as_path(), self.new.oid)); + let old = Some((self.old_path.as_path(), crate::oid::from_surf(self.old.oid))); + let new = Some((self.new_path.as_path(), crate::oid::from_surf(self.new.oid))); let blobs = Blobs::from_paths(old, new, repo); types::diff::Copied { diff --git a/crates/radicle-types/src/traits/repo.rs b/crates/radicle-types/src/traits/repo.rs index edfb05175..db4be9104 100644 --- a/crates/radicle-types/src/traits/repo.rs +++ b/crates/radicle-types/src/traits/repo.rs @@ -1,4 +1,5 @@ use base64::Engine; +use radicle::git::Oid; use radicle_surf as surf; use serde::{Deserialize, Serialize}; @@ -158,13 +159,14 @@ pub trait Repo: Profile { "Readme.md", ]; - let oid = sha.map_or_else(|| repo.head(), Ok)?; + let oid = sha.map_or_else(|| repo.head().map(|oid| Oid::from(*oid)), Ok)?; + for path in paths .iter() .map(ToString::to_string) .chain(paths.iter().map(|p| p.to_lowercase())) { - if let Ok(blob) = repo.blob(oid, &path) { + if let Ok(blob) = repo.blob(crate::oid::into_surf(oid), &path) { if blob.size() > MAX_BLOB_SIZE { return Err(Error::FileTooLarge(blob.size())); } @@ -238,8 +240,8 @@ pub trait Repo: Profile { &profile.storage, &rid, ))?; - let base = repo.commit(base)?; - let commit = repo.commit(head)?; + let base = repo.commit(crate::oid::into_surf(base))?; + let commit = repo.commit(crate::oid::into_surf(head))?; let diff = repo.diff(base.id, commit.id)?; let stats = diff.stats(); @@ -309,8 +311,8 @@ pub trait Repo: Profile { let highlight = options.highlight.unwrap_or(true); let profile = self.profile(); let repo = profile.storage.repository(rid)?.backend; - let base = repo.find_commit(*options.base)?; - let head = repo.find_commit(*options.head)?; + let base = repo.find_commit(options.base.into())?; + let head = repo.find_commit(options.head.into())?; let mut opts = git::raw::DiffOptions::new(); opts.patience(true).minimal(true).context_lines(unified);