use crate::revision;
#[cfg(feature = "revision")]
use crate::{bstr::BStr, Id};
impl crate::Repository {
#[doc(alias = "revparse", alias = "git2")]
#[cfg(feature = "revision")]
pub fn rev_parse<'a>(&self, spec: impl Into<&'a BStr>) -> Result<revision::Spec<'_>, gix_error::Error> {
revision::Spec::from_bstr(
spec,
self,
revision::spec::parse::Options {
object_kind_hint: self.config.object_kind_hint,
..Default::default()
},
)
}
#[doc(alias = "revparse_single", alias = "git2")]
#[cfg(feature = "revision")]
pub fn rev_parse_single<'repo, 'a>(
&'repo self,
spec: impl Into<&'a BStr>,
) -> Result<Id<'repo>, revision::spec::parse::single::Error> {
let spec = spec.into();
self.rev_parse(spec)?
.single()
.ok_or(revision::spec::parse::single::Error::RangedRev { spec: spec.into() })
}
#[cfg(feature = "revision")]
pub fn merge_base(
&self,
one: impl Into<gix_hash::ObjectId>,
two: impl Into<gix_hash::ObjectId>,
) -> Result<Id<'_>, super::merge_base::Error> {
use crate::prelude::ObjectIdExt;
let one = one.into();
let two = two.into();
let cache = self.commit_graph_if_enabled()?;
let mut graph = self.revision_graph(cache.as_ref());
let bases = gix_revision::merge_base(one, &[two], &mut graph)?.ok_or(super::merge_base::Error::NotFound {
first: one,
second: two,
})?;
Ok(bases.first().attach(self))
}
#[cfg(feature = "revision")]
pub fn merge_base_with_graph(
&self,
one: impl Into<gix_hash::ObjectId>,
two: impl Into<gix_hash::ObjectId>,
graph: &mut gix_revwalk::Graph<'_, '_, gix_revwalk::graph::Commit<gix_revision::merge_base::Flags>>,
) -> Result<Id<'_>, super::merge_base_with_graph::Error> {
use crate::prelude::ObjectIdExt;
let one = one.into();
let two = two.into();
let bases =
gix_revision::merge_base(one, &[two], graph)?.ok_or(super::merge_base_with_graph::Error::NotFound {
first: one,
second: two,
})?;
Ok(bases.first().attach(self))
}
#[doc(alias = "merge_bases_many", alias = "git2")]
#[cfg(feature = "revision")]
pub fn merge_bases_many_with_graph(
&self,
one: impl Into<gix_hash::ObjectId>,
others: &[gix_hash::ObjectId],
graph: &mut gix_revwalk::Graph<'_, '_, gix_revwalk::graph::Commit<gix_revision::merge_base::Flags>>,
) -> Result<Vec<Id<'_>>, gix_revision::merge_base::Error> {
use crate::prelude::ObjectIdExt;
let one = one.into();
Ok(match gix_revision::merge_base(one, others, graph)? {
Some(bases) => bases.into_iter().map(|id| id.attach(self)).collect(),
None => Vec::new(),
})
}
#[doc(alias = "git2")]
#[cfg(feature = "revision")]
pub fn merge_bases_many(
&self,
one: impl Into<gix_hash::ObjectId>,
others: &[gix_hash::ObjectId],
) -> Result<Vec<Id<'_>>, crate::repository::merge_bases_many::Error> {
let cache = self.commit_graph_if_enabled()?;
let mut graph = self.revision_graph(cache.as_ref());
Ok(self.merge_bases_many_with_graph(one, others, &mut graph)?)
}
#[cfg(feature = "revision")]
pub fn merge_base_octopus_with_graph(
&self,
commits: impl IntoIterator<Item = impl Into<gix_hash::ObjectId>>,
graph: &mut gix_revwalk::Graph<'_, '_, gix_revwalk::graph::Commit<gix_revision::merge_base::Flags>>,
) -> Result<Id<'_>, crate::repository::merge_base_octopus_with_graph::Error> {
use crate::{prelude::ObjectIdExt, repository::merge_base_octopus_with_graph};
let commits: Vec<_> = commits.into_iter().map(Into::into).collect();
let first = commits
.first()
.copied()
.ok_or(merge_base_octopus_with_graph::Error::MissingCommit)?;
gix_revision::merge_base::octopus(first, &commits[1..], graph)?
.ok_or(merge_base_octopus_with_graph::Error::NoMergeBase)
.map(|id| id.attach(self))
}
#[cfg(feature = "revision")]
pub fn merge_base_octopus(
&self,
commits: impl IntoIterator<Item = impl Into<gix_hash::ObjectId>>,
) -> Result<Id<'_>, crate::repository::merge_base_octopus::Error> {
let cache = self.commit_graph_if_enabled()?;
let mut graph = self.revision_graph(cache.as_ref());
Ok(self.merge_base_octopus_with_graph(commits, &mut graph)?)
}
#[doc(alias = "revwalk", alias = "git2")]
pub fn rev_walk(
&self,
tips: impl IntoIterator<Item = impl Into<gix_hash::ObjectId>>,
) -> revision::walk::Platform<'_> {
revision::walk::Platform::new(tips, self)
}
}