use crate::{bstr::BStr, ext::ReferenceExt, revision::Spec, Id, Reference};
pub mod parse;
mod impls {
use std::ops::{Deref, DerefMut};
use crate::revision::Spec;
impl Deref for Spec<'_> {
type Target = gix_revision::Spec;
fn deref(&self) -> &Self::Target {
&self.inner
}
}
impl DerefMut for Spec<'_> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.inner
}
}
impl PartialEq for Spec<'_> {
fn eq(&self, other: &Self) -> bool {
self.inner == other.inner
}
}
impl Eq for Spec<'_> {}
}
impl<'repo> Spec<'repo> {
pub fn from_id(id: Id<'repo>) -> Self {
Spec {
inner: gix_revision::Spec::Include(id.inner),
path: None,
repo: id.repo,
first_ref: None,
second_ref: None,
}
}
}
impl<'repo> Spec<'repo> {
pub fn detach(self) -> gix_revision::Spec {
self.inner
}
pub fn into_references(self) -> (Option<Reference<'repo>>, Option<Reference<'repo>>) {
let repo = self.repo;
(
self.first_ref.map(|r| r.attach(repo)),
self.second_ref.map(|r| r.attach(repo)),
)
}
pub fn path_and_mode(&self) -> Option<(&BStr, gix_object::tree::EntryMode)> {
self.path.as_ref().map(|(p, mode)| (p.as_ref(), *mode))
}
pub fn first_reference(&self) -> Option<&gix_ref::Reference> {
self.first_ref.as_ref()
}
pub fn second_reference(&self) -> Option<&gix_ref::Reference> {
self.second_ref.as_ref()
}
pub fn single(&self) -> Option<Id<'repo>> {
match self.inner {
gix_revision::Spec::Include(id) | gix_revision::Spec::ExcludeParents(id) => {
Id::from_id(id, self.repo).into()
}
gix_revision::Spec::Exclude(_)
| gix_revision::Spec::Range { .. }
| gix_revision::Spec::Merge { .. }
| gix_revision::Spec::IncludeOnlyParents { .. } => None,
}
}
}