diff --git a/Cargo.lock b/Cargo.lock index 5276dca7f..92a1b25e5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4330,6 +4330,7 @@ dependencies = [ "anyhow", "axum", "base64 0.22.1", + "git2", "infer", "log", "mime-infer", diff --git a/crates/radicle-types/Cargo.toml b/crates/radicle-types/Cargo.toml index 9fdf9ca11..4554bc478 100644 --- a/crates/radicle-types/Cargo.toml +++ b/crates/radicle-types/Cargo.toml @@ -10,6 +10,7 @@ doctest = false anyhow = { version = "1.0.90" } axum = { version = "0.8.1", default-features = false, features = ["json"] } base64 = { version = "0.22.1" } +git2 = { version = "0.20.4", default-features = false, features = ["vendored-libgit2"] } log = { version = "0.4.22" } infer = { version = "0.19.0" } mime-infer = { version = "3.0.0" } diff --git a/crates/radicle-types/src/cobs/stream/iter.rs b/crates/radicle-types/src/cobs/stream/iter.rs index 35b301994..92124f85f 100644 --- a/crates/radicle-types/src/cobs/stream/iter.rs +++ b/crates/radicle-types/src/cobs/stream/iter.rs @@ -7,8 +7,8 @@ use serde_json as json; use radicle::cob::change::Storage; use radicle::cob::{Manifest, Op, TypeName}; -use radicle::git::raw as git2; -use radicle::git::{Oid, PatternString}; +use radicle::git; +use radicle::git::Oid; use radicle::profile::Aliases; use radicle::storage::git::Repository; @@ -30,7 +30,7 @@ pub(super) struct Walk { #[derive(Clone, Debug)] pub enum Until { Tip(Oid), - Glob(PatternString), + Glob(git::fmt::refspec::PatternString), } impl From for Until { @@ -39,8 +39,8 @@ impl From for Until { } } -impl From for Until { - fn from(glob: PatternString) -> Self { +impl From for Until { + fn from(glob: git::fmt::refspec::PatternString) -> Self { Self::Glob(glob) } } @@ -86,14 +86,14 @@ impl Walk { } /// Get the iterator for the walk. - pub(super) fn iter(self, repo: &Repository) -> Result, git2::Error> { + pub(super) fn iter(self, repo: &Repository) -> Result, git::raw::Error> { let mut walk = repo.backend.revwalk()?; // N.b. ensure that we start from the `self.from` commit. walk.set_sorting(git2::Sort::TOPOLOGICAL.union(git2::Sort::REVERSE))?; match self.until { Until::Tip(tip) => walk.push_range(&format!("{}..{}", self.from, tip))?, Until::Glob(glob) => { - walk.push(*self.from)?; + walk.push(git2::Oid::from(self.from))?; walk.push_glob(glob.as_str())? } } @@ -107,13 +107,13 @@ impl Walk { } impl<'a> Iterator for WalkIter<'a> { - type Item = Result, git2::Error>; + type Item = Result, git::raw::Error>; fn next(&mut self) -> Option { // N.b. ensure that we start using the `from` commit and use the revwalk // after that. if let Some(from) = self.from.take() { - return Some(self.repo.backend.find_commit(*from)); + return Some(self.repo.backend.find_commit(git2::Oid::from(from))); } let oid = self.inner.next()?; Some(oid.and_then(|oid| self.repo.backend.find_commit(oid))) @@ -154,7 +154,7 @@ impl<'a, A> ActionsIter<'a, A> { fn matches_manifest(&self, tree: &git2::Tree) -> Result { let entry = match tree.get_path(Path::new("manifest")) { Ok(entry) => entry, - Err(err) if matches!(err.code(), git2::ErrorCode::NotFound) => return Ok(false), + Err(err) if matches!(err.code(), git::raw::ErrorCode::NotFound) => return Ok(false), Err(err) => { return Err(error::Actions::ManifestPath { oid: tree.id().into(), @@ -298,14 +298,14 @@ where /// The entry is only an action if it is a blob and its name is numerical. fn from_tree_entry( repo: &Repository, - entry: git2::TreeEntry, + entry: git2::TreeEntry<'_>, op: Op>, author: Author, ) -> Option, error::TreeAction>> where A: for<'de> Deserialize<'de>, { - let as_action = |entry: git2::TreeEntry| -> Result, error::TreeAction> { + let as_action = |entry: git2::TreeEntry<'_>| -> Result, error::TreeAction> { let object = entry .to_object(&repo.backend) .map_err(|err| error::TreeAction::InvalidEntry { err })?; @@ -322,14 +322,14 @@ where // An entry is only considered an action if it: // a) Is a blob // b) Its name is numeric, e.g. 1, 2, 3, etc. - let is_action = - entry.filemode() == i32::from(git2::FileMode::Blob) && name.chars().all(|c| c.is_numeric()); + let is_action = entry.filemode() == i32::from(git::raw::FileMode::Blob) + && name.chars().all(|c| c.is_numeric()); is_action.then(|| as_action(entry)) } /// Helper to deserialize an action from a blob's contents. fn action( - blob: &git2::Blob, + blob: &git2::Blob<'_>, op: Op>, author: Author, ) -> Result, error::Action>