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.
This commit is contained in:
Lorenz Leutgeb
2026-03-21 18:55:19 +01:00
parent 34706164e5
commit eba37c01fa
9 changed files with 43 additions and 25 deletions
+1 -1
View File
@@ -152,7 +152,7 @@ pub struct DiffFile {
impl From<surf::diff::DiffFile> for DiffFile {
fn from(value: surf::diff::DiffFile) -> Self {
Self {
oid: value.oid,
oid: crate::oid::from_surf(value.oid),
mode: value.mode.into(),
}
}
+1
View File
@@ -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;
+7
View File
@@ -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))
}
+6 -2
View File
@@ -172,12 +172,16 @@ pub struct Commit {
impl From<surf::Commit> 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(),
}
}
}
+1 -1
View File
@@ -35,7 +35,7 @@ impl<T: AsRef<[u8]>> From<surf::blob::Blob<T>> 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,
+6 -2
View File
@@ -23,12 +23,16 @@ pub struct Commit {
impl From<surf::Commit> 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::<Vec<_>>(),
parents: commit
.parents
.into_iter()
.map(crate::oid::from_surf)
.collect::<Vec<_>>(),
}
}
}
+4 -4
View File
@@ -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),
}
}
}
+9 -9
View File
@@ -531,7 +531,7 @@ pub trait Repo {
impl Repo for git::raw::Repository {
fn blob(&self, oid: git::Oid) -> Result<Blob, git::raw::Error> {
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<R: Repo>(&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<R: Repo>(&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<R: Repo>(&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<R: Repo>(&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<R: Repo>(&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 {
+8 -6
View File
@@ -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);