mod remote;
mod spec;
mod vcs;
pub mod adapters;
pub mod path;
pub mod revision;
pub mod types;
use std::borrow::Cow;
use bytes::Bytes;
use relative_path::{RelativePath, RelativePathBuf};
pub use self::remote::Remote;
pub use self::spec::{Error as RepoSpecError, RepoSpec, ShortRepoSpec};
pub use self::vcs::GitLike;
pub trait Repository {
type Error;
fn get_file(&self, path: impl AsRef<RelativePath>) -> Result<Option<Bytes>, Self::Error>;
fn get_index(&self) -> Result<impl Iterator<Item = Cow<'_, RelativePath>>, Self::Error>;
}
impl<T> Repository for &T
where
T: Repository,
{
type Error = T::Error;
fn get_file(&self, path: impl AsRef<RelativePath>) -> Result<Option<Bytes>, Self::Error> {
(**self).get_file(path)
}
fn get_index(&self) -> Result<impl Iterator<Item = Cow<'_, RelativePath>>, Self::Error> {
(**self).get_index()
}
}
impl<T> Repository for &mut T
where
T: Repository,
{
type Error = T::Error;
fn get_file(&self, path: impl AsRef<RelativePath>) -> Result<Option<Bytes>, Self::Error> {
(**self).get_file(path)
}
fn get_index(&self) -> Result<impl Iterator<Item = Cow<'_, RelativePath>>, Self::Error> {
(**self).get_index()
}
}
pub trait Stage: Repository {
fn add_file(
&mut self,
path: impl Into<RelativePathBuf>,
file: impl Into<Bytes>,
) -> Result<&mut Self, Self::Error>;
fn add_files(
&mut self,
files: impl IntoIterator<Item = (RelativePathBuf, Bytes)>,
) -> Result<&mut Self, Self::Error> {
for (path, file) in files {
self.add_file(path, file)?;
}
Ok(self)
}
fn with_file(
mut self,
path: impl Into<RelativePathBuf>,
file: impl Into<Bytes>,
) -> Result<Self, Self::Error>
where
Self: Sized,
{
self.add_file(path, file)?;
Ok(self)
}
fn with_files(
mut self,
files: impl IntoIterator<Item = (RelativePathBuf, Bytes)>,
) -> Result<Self, Self::Error>
where
Self: Sized,
{
self.add_files(files)?;
Ok(self)
}
fn remove_file(&mut self, path: impl AsRef<RelativePath>)
-> Result<Option<Bytes>, Self::Error>;
}
impl<T> Stage for &mut T
where
T: Stage,
{
fn add_file(
&mut self,
path: impl Into<RelativePathBuf>,
file: impl Into<Bytes>,
) -> Result<&mut Self, Self::Error> {
(**self).add_file(path, file)?;
Ok(self)
}
fn remove_file(
&mut self,
path: impl AsRef<RelativePath>,
) -> Result<Option<Bytes>, Self::Error> {
(**self).remove_file(path)
}
}
pub trait Commit: Stage {
type Params;
fn commit(&mut self, params: impl Into<Self::Params>) -> Result<(), Self::Error>;
fn committed(mut self, params: impl Into<Self::Params>) -> Result<Self, Self::Error>
where
Self: Sized,
{
self.commit(params)?;
Ok(self)
}
}
impl<T> Commit for &mut T
where
T: Commit,
{
type Params = T::Params;
fn commit(&mut self, params: impl Into<Self::Params>) -> Result<(), Self::Error> {
(**self).commit(params)
}
}
pub trait Open: Repository + Sized {
type Context;
fn open<T, E>(ctx: T) -> Result<Self, Self::Error>
where
T: TryInto<Self::Context, Error = E>,
E: Into<Self::Error>;
}