-
-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
repository(doc): easy::object, sans a few child-modules (#164)
- Loading branch information
Showing
4 changed files
with
150 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#![allow(missing_docs)] | ||
/// | ||
pub mod find { | ||
|
||
use crate::easy; | ||
|
||
pub(crate) type OdbError = git_odb::compound::find::Error; | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
pub enum Error { | ||
#[error(transparent)] | ||
Find(#[from] OdbError), | ||
#[error("BUG: Part of interior state could not be borrowed.")] | ||
BorrowState(#[from] easy::borrow::state::Error), | ||
#[error("BUG: The repository could not be borrowed")] | ||
BorrowRepo(#[from] easy::borrow::repo::Error), | ||
} | ||
|
||
pub mod existing { | ||
use crate::easy; | ||
|
||
pub(crate) type OdbError = git_odb::pack::find::existing::Error<git_odb::compound::find::Error>; | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
pub enum Error { | ||
#[error(transparent)] | ||
FindExisting(#[from] OdbError), | ||
#[error("BUG: Part of interior state could not be borrowed.")] | ||
BorrowState(#[from] easy::borrow::state::Error), | ||
#[error("BUG: The repository could not be borrowed")] | ||
BorrowRepo(#[from] easy::borrow::repo::Error), | ||
} | ||
} | ||
} | ||
|
||
pub mod write { | ||
use crate::easy; | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
pub enum Error { | ||
#[error(transparent)] | ||
OdbWrite(#[from] git_odb::loose::write::Error), | ||
#[error("BUG: The repository could not be borrowed")] | ||
BorrowRepo(#[from] easy::borrow::repo::Error), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#![allow(missing_docs)] | ||
use crate::{ | ||
easy, | ||
easy::{ | ||
ext::ObjectAccessExt, | ||
object, | ||
object::{peel, Kind}, | ||
ObjectRef, | ||
}, | ||
}; | ||
|
||
pub mod to_kind { | ||
mod error { | ||
|
||
use crate::easy::object; | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
pub enum Error { | ||
#[error(transparent)] | ||
FindExistingObject(#[from] object::find::existing::Error), | ||
#[error("Last encountered object kind was {} while trying to peel to {}", .actual, .expected)] | ||
NotFound { | ||
actual: object::Kind, | ||
expected: object::Kind, | ||
}, | ||
} | ||
} | ||
pub use error::Error; | ||
} | ||
|
||
impl<'repo, A> ObjectRef<'repo, A> | ||
where | ||
A: easy::Access + Sized, | ||
{ | ||
// TODO: tests | ||
pub fn peel_to_kind(mut self, kind: Kind) -> Result<Self, peel::to_kind::Error> { | ||
loop { | ||
match self.kind { | ||
any_kind if kind == any_kind => { | ||
return Ok(self); | ||
} | ||
Kind::Commit => { | ||
let tree_id = self.to_commit_iter().expect("commit").tree_id().expect("valid commit"); | ||
let access = self.access; | ||
drop(self); | ||
self = access.find_object(tree_id)?; | ||
} | ||
Kind::Tag => { | ||
let target_id = self.to_tag_iter().expect("tag").target_id().expect("valid tag"); | ||
let access = self.access; | ||
drop(self); | ||
self = access.find_object(target_id)?; | ||
} | ||
Kind::Tree | Kind::Blob => { | ||
return Err(peel::to_kind::Error::NotFound { | ||
actual: self.kind, | ||
expected: kind, | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
|
||
// TODO: tests | ||
pub fn peel_to_end(mut self) -> Result<Self, object::find::existing::Error> { | ||
loop { | ||
match self.kind { | ||
Kind::Commit | Kind::Tree | Kind::Blob => break Ok(self), | ||
Kind::Tag => { | ||
let target_id = self.to_tag_iter().expect("tag").target_id().expect("valid tag"); | ||
let access = self.access; | ||
drop(self); | ||
self = access.find_object(target_id)?; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters