diff --git a/gix/src/repository/mod.rs b/gix/src/repository/mod.rs index caa98f1613e..92a9545e3a6 100644 --- a/gix/src/repository/mod.rs +++ b/gix/src/repository/mod.rs @@ -219,6 +219,20 @@ pub mod merge_base_octopus { } } +/// +#[cfg(feature = "revision")] +pub mod merge_bases_many { + /// The error returned by [Repository::merge_bases_many()](crate::Repository::merge_bases_many()). + #[derive(Debug, thiserror::Error)] + #[allow(missing_docs)] + pub enum Error { + #[error(transparent)] + OpenCache(#[from] crate::repository::commit_graph_if_enabled::Error), + #[error(transparent)] + MergeBase(#[from] gix_revision::merge_base::Error), + } +} + /// #[cfg(feature = "merge")] pub mod tree_merge_options { diff --git a/gix/src/repository/revision.rs b/gix/src/repository/revision.rs index ca89cd1f166..72d677b72f0 100644 --- a/gix/src/repository/revision.rs +++ b/gix/src/repository/revision.rs @@ -82,11 +82,11 @@ impl crate::Repository { Ok(bases[0].attach(self)) } - /// Obtain all merge-bases between commit `one` and `others`, or an empty list if there is none, providing a - /// commit-graph `graph` to potentially greatly accelerate the operation. + /// Get all merge-bases between commit `one` and `others`, or an empty list if there is none, providing a + /// commit-graph `graph` to potentially greatly speed up the operation. /// /// # Performance - /// Be sure to [set an object cache](crate::Repository::object_cache_size_if_unset) to accelerate repeated commit lookups. + /// Be sure to [set an object cache](crate::Repository::object_cache_size_if_unset) to speed up repeated commit lookups. #[doc(alias = "merge_bases_many", alias = "git2")] #[cfg(feature = "revision")] pub fn merge_bases_many_with_graph( @@ -104,6 +104,24 @@ impl crate::Repository { .collect()) } + /// Like [`merge_bases_many_with_graph()`](Self::merge_bases_many_with_graph), but without the ability to speed up consecutive calls with a [graph](gix_revwalk::Graph). + /// + /// # Performance + /// + /// Be sure to [set an object cache](crate::Repository::object_cache_size_if_unset) to speed up repeated commit lookups, and consider + /// using [`merge_bases_many_with_graph()`](Self::merge_bases_many_with_graph) for consecutive calls. + #[doc(alias = "git2")] + #[cfg(feature = "revision")] + pub fn merge_bases_many( + &self, + one: impl Into, + others: &[gix_hash::ObjectId], + ) -> Result>, 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)?) + } + /// Return the best merge-base among all `commits`, or fail if `commits` yields no commit or no merge-base was found. /// /// Use `graph` to speed up repeated calls.