@@ -104,6 +104,40 @@ impl crate::Repository {
104104 . collect ( ) )
105105 }
106106
107+ /// Return the best merge-base among all `commits`, or fail if `commits` yields no commit or no merge-base was found.
108+ ///
109+ /// Use `graph` to speed up repeated calls.
110+ #[ cfg( feature = "revision" ) ]
111+ pub fn merge_base_octopus_with_graph (
112+ & self ,
113+ commits : impl IntoIterator < Item = impl Into < gix_hash:: ObjectId > > ,
114+ graph : & mut gix_revwalk:: Graph < ' _ , ' _ , gix_revwalk:: graph:: Commit < gix_revision:: merge_base:: Flags > > ,
115+ ) -> Result < Id < ' _ > , crate :: repository:: merge_base_octopus_with_graph:: Error > {
116+ use crate :: prelude:: ObjectIdExt ;
117+ use crate :: repository:: merge_base_octopus_with_graph;
118+ let commits: Vec < _ > = commits. into_iter ( ) . map ( Into :: into) . collect ( ) ;
119+ let first = commits
120+ . first ( )
121+ . copied ( )
122+ . ok_or ( merge_base_octopus_with_graph:: Error :: MissingCommit ) ?;
123+ gix_revision:: merge_base:: octopus ( first, & commits[ 1 ..] , graph) ?
124+ . ok_or ( merge_base_octopus_with_graph:: Error :: NoMergeBase )
125+ . map ( |id| id. attach ( self ) )
126+ }
127+
128+ /// Return the best merge-base among all `commits`, or fail if `commits` yields no commit or no merge-base was found.
129+ ///
130+ /// For repeated calls, prefer [`Self::merge_base_octopus_with_graph()`] for cache-reuse.
131+ #[ cfg( feature = "revision" ) ]
132+ pub fn merge_base_octopus (
133+ & self ,
134+ commits : impl IntoIterator < Item = impl Into < gix_hash:: ObjectId > > ,
135+ ) -> Result < Id < ' _ > , crate :: repository:: merge_base_octopus:: Error > {
136+ let cache = self . commit_graph_if_enabled ( ) ?;
137+ let mut graph = self . revision_graph ( cache. as_ref ( ) ) ;
138+ Ok ( self . merge_base_octopus_with_graph ( commits, & mut graph) ?)
139+ }
140+
107141 /// Create the baseline for a revision walk by initializing it with the `tips` to start iterating on.
108142 ///
109143 /// It can be configured further before starting the actual walk.
0 commit comments