#[cfg(any(feature = "blocking-client", feature = "async-client"))]
pub mod init;
#[derive(Debug, Clone)]
pub enum Source {
ObjectId(gix_hash::ObjectId),
Ref(crate::handshake::Ref),
}
impl Source {
pub fn as_id(&self) -> Option<&gix_hash::oid> {
match self {
Source::ObjectId(id) => Some(id),
Source::Ref(r) => r.unpack().1,
}
}
pub fn as_target(&self) -> Option<&bstr::BStr> {
match self {
Source::ObjectId(_) => None,
Source::Ref(r) => match r {
crate::handshake::Ref::Peeled { .. } | crate::handshake::Ref::Direct { .. } => None,
crate::handshake::Ref::Symbolic { target, .. } | crate::handshake::Ref::Unborn { target, .. } => {
Some(target.as_ref())
}
},
}
}
pub fn peeled_id(&self) -> Option<&gix_hash::oid> {
match self {
Source::ObjectId(id) => Some(id),
Source::Ref(r) => {
let (_name, target, peeled) = r.unpack();
peeled.or(target)
}
}
}
pub fn as_name(&self) -> Option<&bstr::BStr> {
match self {
Source::ObjectId(_) => None,
Source::Ref(r) => match r {
crate::handshake::Ref::Unborn { full_ref_name, .. }
| crate::handshake::Ref::Symbolic { full_ref_name, .. }
| crate::handshake::Ref::Direct { full_ref_name, .. }
| crate::handshake::Ref::Peeled { full_ref_name, .. } => Some(full_ref_name.as_ref()),
},
}
}
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub enum SpecIndex {
ExplicitInRemote(usize),
Implicit(usize),
}
impl SpecIndex {
pub fn get<'a>(
self,
refspecs: &'a [gix_refspec::RefSpec],
extra_refspecs: &'a [gix_refspec::RefSpec],
) -> Option<&'a gix_refspec::RefSpec> {
match self {
SpecIndex::ExplicitInRemote(idx) => refspecs.get(idx),
SpecIndex::Implicit(idx) => extra_refspecs.get(idx),
}
}
pub fn implicit_index(self) -> Option<usize> {
match self {
SpecIndex::Implicit(idx) => Some(idx),
SpecIndex::ExplicitInRemote(_) => None,
}
}
}
#[derive(Debug, Clone)]
pub struct Mapping {
pub remote: Source,
pub local: Option<bstr::BString>,
pub spec_index: SpecIndex,
}