|
| 1 | +use crate::prelude::ObjectIdExt; |
| 2 | +use crate::repository::{merge_base_octopus, merge_base_octopus_with_graph}; |
1 | 3 | use crate::revision;
|
2 | 4 | #[cfg(feature = "revision")]
|
3 | 5 | use crate::{bstr::BStr, Id};
|
@@ -104,6 +106,38 @@ impl crate::Repository {
|
104 | 106 | .collect())
|
105 | 107 | }
|
106 | 108 |
|
| 109 | + /// Return the best merge-base among all `commits`, or fail if `commits` yields no commit or no merge-base was found. |
| 110 | + /// |
| 111 | + /// Use `graph` to speed up repeated calls. |
| 112 | + #[cfg(feature = "revision")] |
| 113 | + pub fn merge_base_octopus_with_graph( |
| 114 | + &self, |
| 115 | + commits: impl IntoIterator<Item = impl Into<gix_hash::ObjectId>>, |
| 116 | + graph: &mut gix_revwalk::Graph<'_, '_, gix_revwalk::graph::Commit<gix_revision::merge_base::Flags>>, |
| 117 | + ) -> Result<Id<'_>, merge_base_octopus_with_graph::Error> { |
| 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<'_>, 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 | + |
107 | 141 | /// Create the baseline for a revision walk by initializing it with the `tips` to start iterating on.
|
108 | 142 | ///
|
109 | 143 | /// It can be configured further before starting the actual walk.
|
|
0 commit comments