1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
/// An object header informing about object properties, without it being fully decoded in the process.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum Header {
/// The object was not packed, but is currently located in the loose object portion of the database.
///
/// As packs are searched first, this means that in this very moment, the object whose header we retrieved is unique
/// in the object database.
Loose {
/// The kind of the object.
kind: gix_object::Kind,
/// The size of the object's data in bytes.
size: u64,
},
/// The object was present in a pack.
///
/// Note that this does not imply it is unique in the database, as it might be present in more than one pack and even
/// as loose object.
Packed(gix_pack::data::decode::header::Outcome),
}
mod header {
use super::Header;
impl Header {
/// Return the object kind of the object we represent.
pub fn kind(&self) -> gix_object::Kind {
match self {
Header::Packed(out) => out.kind,
Header::Loose { kind, .. } => *kind,
}
}
/// Return the size of the object in bytes.
pub fn size(&self) -> u64 {
match self {
Header::Packed(out) => out.object_size,
Header::Loose { size, .. } => *size,
}
}
/// Return the amount of deltas decoded to obtain this header, if the object was packed.
pub fn num_deltas(&self) -> Option<u32> {
match self {
Header::Packed(out) => out.num_deltas.into(),
Header::Loose { .. } => None,
}
}
}
impl From<gix_pack::data::decode::header::Outcome> for Header {
fn from(packed_header: gix_pack::data::decode::header::Outcome) -> Self {
Header::Packed(packed_header)
}
}
impl From<(u64, gix_object::Kind)> for Header {
fn from((object_size, kind): (u64, gix_object::Kind)) -> Self {
Header::Loose {
kind,
size: object_size,
}
}
}
}