Radish alpha
r
rad:z4D5UCArafTzTQpDZNQRuqswh3ury
Radicle desktop app
Radicle
Git
radicle-types: Fix OID conversion
Lorenz Leutgeb committed 1 month ago
commit eba37c01faeaf2e533327a5d48f2d55dc1fa517c
parent 3470616
9 files changed +43 -25
modified crates/radicle-types/src/diff.rs
@@ -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(),
        }
    }
modified 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;
added 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))
+
}
modified crates/radicle-types/src/repo.rs
@@ -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(),
        }
    }
}
modified crates/radicle-types/src/source/blob.rs
@@ -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,
modified crates/radicle-types/src/source/commit.rs
@@ -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<_>>(),
        }
    }
}
modified 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),
        }
    }
}
modified 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<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 {
modified 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);