#![cfg_attr(
feature = "document-features",
cfg_attr(doc, doc = ::document_features::document_features!())
)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![deny(missing_docs, rust_2018_idioms, unsafe_code)]
use std::{
cell::RefCell,
path::PathBuf,
sync::{atomic::AtomicUsize, Arc},
};
use arc_swap::ArcSwap;
use git_features::{threading::OwnShared, zlib::stream::deflate};
pub use git_pack as pack;
mod store_impls;
pub use store_impls::{dynamic as store, loose};
pub mod alternate;
pub struct Cache<S> {
inner: S,
new_pack_cache: Option<Arc<cache::NewPackCacheFn>>,
new_object_cache: Option<Arc<cache::NewObjectCacheFn>>,
pack_cache: Option<RefCell<Box<cache::PackCache>>>,
object_cache: Option<RefCell<Box<cache::ObjectCache>>>,
}
pub mod cache;
pub struct Sink {
compressor: Option<RefCell<deflate::Write<std::io::Sink>>>,
object_hash: git_hash::Kind,
}
pub fn sink(object_hash: git_hash::Kind) -> Sink {
Sink {
compressor: None,
object_hash,
}
}
pub mod sink;
pub mod find;
mod traits;
pub use traits::{Find, FindExt, Header, HeaderExt, Write};
pub type Handle = Cache<store::Handle<OwnShared<Store>>>;
pub type HandleArc = Cache<store::Handle<Arc<Store>>>;
use store::types;
pub struct Store {
write: parking_lot::Mutex<()>,
pub(crate) path: PathBuf,
pub(crate) current_dir: PathBuf,
pub(crate) replacements: Vec<(git_hash::ObjectId, git_hash::ObjectId)>,
pub(crate) index: ArcSwap<types::SlotMapIndex>,
pub(crate) files: Vec<types::MutableIndexAndPack>,
pub(crate) num_handles_stable: AtomicUsize,
pub(crate) num_handles_unstable: AtomicUsize,
pub(crate) num_disk_state_consolidation: AtomicUsize,
use_multi_pack_index: bool,
object_hash: git_hash::Kind,
}
pub fn at_opts(
objects_dir: impl Into<PathBuf>,
replacements: impl IntoIterator<Item = (git_hash::ObjectId, git_hash::ObjectId)>,
options: store::init::Options,
) -> std::io::Result<Handle> {
let handle = OwnShared::new(Store::at_opts(objects_dir, replacements, options)?).to_handle();
Ok(Cache::from(handle))
}
pub fn at(objects_dir: impl Into<PathBuf>) -> std::io::Result<Handle> {
at_opts(objects_dir, Vec::new().into_iter(), Default::default())
}