use std::path::{Path, PathBuf};
pub use self::blame::{Blame, BlameLine};
pub use self::checkout::CheckoutOptions;
pub use self::clone::CloneOptions;
pub use self::diff::{ChangeKind, Diff, FileChange};
pub use self::error::RepoError;
pub use self::fetch::FetchOptions;
pub use self::init::InitOptions;
pub use self::push::PushOptions;
pub use self::status::RepoStatus;
pub use self::walk::{CommitInfo, CommitWalk};
pub(crate) mod auth;
mod blame;
mod checkout;
mod clone;
mod commit;
mod diff;
mod error;
mod fetch;
mod init;
mod push;
mod status;
mod walk;
#[derive(Debug, Clone)]
pub struct Repo {
inner: gix::ThreadSafeRepository,
path: PathBuf,
}
impl Repo {
pub async fn open(path: impl AsRef<Path>) -> Result<Self, RepoError> {
let path: PathBuf = path.as_ref().to_path_buf();
let path_for_task = path.clone();
tokio::task::spawn_blocking(move || {
let repo = gix::open(&path_for_task).map_err(|e| RepoError::OpenFailed {
path: path_for_task.clone(),
cause: e.to_string(),
})?;
Ok::<_, RepoError>(Self::from_thread_safe(repo.into_sync(), path_for_task))
})
.await
.map_err(|join_err| RepoError::OpenFailed {
path: path.clone(),
cause: format!("spawn_blocking join error: {join_err}"),
})?
}
pub(crate) const fn from_thread_safe(inner: gix::ThreadSafeRepository, path: PathBuf) -> Self {
Self { inner, path }
}
#[must_use]
pub fn path(&self) -> &Path {
&self.path
}
pub(crate) fn thread_safe(&self) -> gix::ThreadSafeRepository {
self.inner.clone()
}
}