use std::fmt::Display;
use tame_index::external::gix;
#[cfg_attr(docsrs, doc(cfg(feature = "git")))]
#[derive(Debug, PartialEq, Eq, Ord, PartialOrd, Clone, Copy)]
pub struct CommitHash {
hash: gix::ObjectId,
}
impl CommitHash {
pub(crate) fn to_gix(self) -> gix::ObjectId {
self.hash
}
pub(crate) fn from_gix(hash: gix::ObjectId) -> Self {
CommitHash { hash }
}
#[inline]
pub fn as_bytes(&self) -> &[u8] {
self.hash.as_bytes()
}
#[inline]
pub fn to_hex(&self) -> String {
self.hash.to_hex().to_string()
}
#[inline]
pub fn is_empty_blob(&self) -> bool {
self.hash.is_empty_blob()
}
#[inline]
pub fn is_empty_tree(&self) -> bool {
self.hash.is_empty_tree()
}
}
impl Display for CommitHash {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.hash.fmt(f)
}
}