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 memmap2::Mmap;
#[derive(PartialEq, Eq, Ord, PartialOrd, Debug, Hash, Clone, Copy)]
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
#[allow(missing_docs)]
pub enum Version {
V1 = 1,
V2 = 2,
}
impl Default for Version {
fn default() -> Self {
Version::V2
}
}
impl Version {
pub fn hash(&self) -> git_hash::Kind {
match self {
Version::V1 | Version::V2 => git_hash::Kind::Sha1,
}
}
}
pub type PrefixLookupResult = Result<EntryIndex, ()>;
pub type EntryIndex = u32;
const FAN_LEN: usize = 256;
pub struct File {
data: Mmap,
path: std::path::PathBuf,
version: Version,
num_objects: u32,
fan: [u32; FAN_LEN],
hash_len: usize,
object_hash: git_hash::Kind,
}
impl File {
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) -> git_hash::Kind {
self.object_hash
}
}
const V2_SIGNATURE: &[u8] = b"\xfftOc";
pub mod init;
pub(crate) mod access;
pub use access::Entry;
pub mod traverse;
mod util;
pub mod verify;
pub mod write;