macro_rules! izip {
( @closure $p:pat => $tup:expr ) => {
|$p| $tup
};
( @closure $p:pat => ( $($tup:tt)* ) , $_iter:expr $( , $tail:expr )* ) => {
izip!(@closure ($p, b) => ( $($tup)*, b ) $( , $tail )*)
};
($first:expr $(,)*) => {
std::iter::IntoIterator::into_iter($first)
};
($first:expr, $second:expr $(,)*) => {
izip!($first)
.zip($second)
};
( $first:expr $( , $rest:expr )* $(,)* ) => {
izip!($first)
$(
.zip($rest)
)*
.map(
izip!(@closure a => (a) $( , $rest )*)
)
};
}
use crate::MMap;
#[derive(Default, PartialEq, Eq, Ord, PartialOrd, Debug, Hash, Clone, Copy)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[allow(missing_docs)]
pub enum Version {
V1 = 1,
#[default]
V2 = 2,
}
impl Version {
pub fn hash(&self) -> gix_hash::Kind {
match self {
Version::V1 | Version::V2 => gix_hash::Kind::Sha1,
}
}
}
pub type PrefixLookupResult = Result<EntryIndex, ()>;
pub type EntryIndex = u32;
const FAN_LEN: usize = 256;
pub struct File<T = MMap> {
data: T,
path: std::path::PathBuf,
version: Version,
num_objects: u32,
fan: [u32; FAN_LEN],
hash_len: usize,
object_hash: gix_hash::Kind,
}
impl<T> File<T>
where
T: crate::FileData,
{
pub fn version(&self) -> Version {
self.version
}
pub fn path(&self) -> &std::path::Path {
&self.path
}
pub fn num_objects(&self) -> EntryIndex {
self.num_objects
}
pub fn object_hash(&self) -> gix_hash::Kind {
self.object_hash
}
}
const V2_SIGNATURE: &[u8] = b"\xfftOc";
pub mod init;
pub(crate) mod access;
pub use access::Entry;
pub(crate) mod encode;
pub mod traverse;
mod util;
pub mod verify;
#[cfg(feature = "streaming-input")]
pub mod write;
#[cfg(feature = "streaming-input")]
pub use write::function::write_data_iter_to_stream;