@@ -2467,6 +2467,38 @@ impl Repository {
24672467 }
24682468
24692469 /// Find a merge base given a list of commits
2470+ ///
2471+ /// This behaves similar to [`git merge-base`](https://git-scm.com/docs/git-merge-base#_discussion).
2472+ /// Given three commits `a`, `b`, and `c`, `merge_base_many(&[a, b, c])`
2473+ /// will compute a hypothetical commit `m`, which is a merge between `b`
2474+ /// and `c`.
2475+ ///
2476+ /// For example, with the following topology:
2477+ /// ```text
2478+ /// o---o---o---o---C
2479+ /// /
2480+ /// / o---o---o---B
2481+ /// / /
2482+ /// ---2---1---o---o---o---A
2483+ /// ```
2484+ ///
2485+ /// the result of `merge_base_many(&[a, b, c])` is 1. This is because the
2486+ /// equivalent topology with a merge commit `m` between `b` and `c` would
2487+ /// is:
2488+ /// ```text
2489+ /// o---o---o---o---o
2490+ /// / \
2491+ /// / o---o---o---o---M
2492+ /// / /
2493+ /// ---2---1---o---o---o---A
2494+ /// ```
2495+ ///
2496+ /// and the result of `merge_base_many(&[a, m])` is 1.
2497+ ///
2498+ /// ---
2499+ ///
2500+ /// If you're looking to recieve the common merge base between all the
2501+ /// given commits, use [`Self::merge_base_octopus`].
24702502 pub fn merge_base_many ( & self , oids : & [ Oid ] ) -> Result < Oid , Error > {
24712503 let mut raw = raw:: git_oid {
24722504 id : [ 0 ; raw:: GIT_OID_RAWSZ ] ,
@@ -2483,6 +2515,23 @@ impl Repository {
24832515 }
24842516 }
24852517
2518+ /// Find a common merge base between all given a list of commits
2519+ pub fn merge_base_octopus ( & self , oids : & [ Oid ] ) -> Result < Oid , Error > {
2520+ let mut raw = raw:: git_oid {
2521+ id : [ 0 ; raw:: GIT_OID_RAWSZ ] ,
2522+ } ;
2523+
2524+ unsafe {
2525+ try_call ! ( raw:: git_merge_base_octopus(
2526+ & mut raw,
2527+ self . raw,
2528+ oids. len( ) as size_t,
2529+ oids. as_ptr( ) as * const raw:: git_oid
2530+ ) ) ;
2531+ Ok ( Binding :: from_raw ( & raw as * const _) )
2532+ }
2533+ }
2534+
24862535 /// Find all merge bases between two commits
24872536 pub fn merge_bases ( & self , one : Oid , two : Oid ) -> Result < OidArray , Error > {
24882537 let mut arr = raw:: git_oidarray {
@@ -3825,6 +3874,10 @@ mod tests {
38253874 // the merge base of (oid2,oid3,oid4) should be oid1
38263875 let merge_base = repo. merge_base_many ( & [ oid2, oid3, oid4] ) . unwrap ( ) ;
38273876 assert_eq ! ( merge_base, oid1) ;
3877+
3878+ // the octopus merge base of (oid2,oid3,oid4) should be oid1
3879+ let merge_base = repo. merge_base_octopus ( & [ oid2, oid3, oid4] ) . unwrap ( ) ;
3880+ assert_eq ! ( merge_base, oid1) ;
38283881 }
38293882
38303883 /// create an octopus:
0 commit comments