Sebastian Thiel[git-repository] better docsf60a7c55 years agoHistory
117 lines · 3.5 KB · Rust
RawDownload
//! This crate provides the [`Repository`] abstraction which serves as a hub into all the functionality of git.//!//! It's powerful and won't sacrifice performance while still increasing convenience compared to using the sub-crates//! individually. Sometimes it may hide complexity under the assumption that the performance difference doesn't matter//! for all but the fewest tools out there, which would be using the underlying crates directly or file an issue.//!//! # The prelude and extensions//!//! With `use git_repository::prelude::*` you should be ready to go as it pulls in various extension traits to make functionality//! available on objects that may use it.//!//! The method signatures are still complex and may require various arguments for configuration and cache control.//!//! ## Easy-Mode//!//! Most extensions to existing objects provide an `obj_with_extension.easy(&repo).an_easier_version_of_a_method()` or `easy(&repo)`//! method to hide all complex arguments and sacrifice some performance for a lot of convenience.//!//! When starting out, use `easy(…)` and migrate to the more detailed method signatures to squeeze out more performance.//!//! # Cargo-features//!//! ## One-stop-shop//!//! To make using  _sub-crates_ easier these are re-exported into the root of this crate.//!//! `git_repository::`//! * [`hash`]//! * [`object`]//!   * [`bstr`][object::bstr]//! * [`odb`]//!   * [`pack`][odb::pack]//! * [`refs`]//! * [`traverse`]//! * [`diff`]//! * [`Progress`]//! * [`progress`]//! * [`interrupt`]//! * [`protocol`]//!   * [`transport`][protocol::transport]//!#![forbid(unsafe_code)]#![deny(rust_2018_idioms)]#![allow(missing_docs)] use std::path::PathBuf; // Re-exports to make this a potential one-stop shop crate avoiding people from having to reference various crates themselves.// This also means that their major version changes affect our major version, but that's alright as we directly expose their// APIs/instances anyway.#[cfg(feature = "git-diff")]pub use git_diff as diff;#[cfg(feature = "git-features")]pub use git_features::{interrupt, progress, progress::Progress};#[cfg(feature = "git-hash")]pub use git_hash as hash;#[cfg(feature = "git-object")]pub use git_object as object;pub use git_odb as odb;#[cfg(feature = "git-protocol")]pub use git_protocol as protocol;pub use git_ref as refs;#[cfg(feature = "git-traverse")]pub use git_traverse as traverse; #[cfg(feature = "one-stop-shop")]pub mod ext;pub mod prelude {    #[cfg(feature = "one-stop-shop")]    pub use crate::ext::*;    pub use git_odb::{Find, FindExt, Write};} pub mod init; pub mod path;pub use path::Path; pub mod repository; pub struct Repository {    pub refs: git_ref::file::Store,    pub working_tree: Option<PathBuf>,    pub odb: git_odb::linked::Store,} impl Repository {    pub fn kind(&self) -> Kind {        match self.working_tree {            Some(_) => Kind::WorkingTree,            None => Kind::Bare,        }    }     pub fn git_dir(&self) -> &std::path::Path {        &self.refs.base    }    pub fn objects_dir(&self) -> &std::path::Path {        &self.odb.dbs[0].loose.path    }} #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]pub enum Kind {    Bare,    WorkingTree,} impl Kind {    pub fn is_bare(&self) -> bool {        matches!(self, Kind::Bare)    }} pub fn discover(directory: impl AsRef<std::path::Path>) -> Result<Repository, repository::discover::Error> {    Repository::discover(directory)}