Skip to content

Commit 3157d80

Browse files
committed
When using the cache, allow using the entire graph.
That way, multiple calls to merge-base can be more optimal. Note that this is a breaking change, but there wasn't a release yet so there is no need to mark it.
1 parent 362770f commit 3157d80

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

gitoxide-core/src/repository/merge_base.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ pub fn merge_base(
2020
.collect::<Result<_, _>>()?;
2121

2222
let cache = repo.commit_graph_if_enabled()?;
23-
let bases = repo.merge_bases_many_with_cache(first_id, &other_ids, cache.as_ref())?;
23+
let mut graph = repo.revision_graph(cache.as_ref());
24+
let bases = repo.merge_bases_many_with_graph(first_id, &other_ids, &mut graph)?;
2425
if bases.is_empty() {
2526
bail!("No base found for {first} and {others}", others = others.join(", "))
2627
}

gix/src/repository/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ pub mod merge_base {
9393

9494
///
9595
#[cfg(feature = "revision")]
96-
pub mod merge_base_with_cache {
97-
/// The error returned by [Repository::merge_base_with_cache()](crate::Repository::merge_base_with_cache()).
96+
pub mod merge_base_with_graph {
97+
/// The error returned by [Repository::merge_base_with_cache()](crate::Repository::merge_base_with_graph()).
9898
#[derive(Debug, thiserror::Error)]
9999
#[allow(missing_docs)]
100100
pub enum Error {

gix/src/repository/revision.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl crate::Repository {
3939
/// Obtain the best merge-base between commit `one` and `two`, or fail if there is none.
4040
///
4141
/// # Performance
42-
/// For repeated calls, prefer [`merge_base_with_cache()`](crate::Repository::merge_base_with_cache()).
42+
/// For repeated calls, prefer [`merge_base_with_cache()`](crate::Repository::merge_base_with_graph()).
4343
/// Also be sure to [set an object cache](crate::Repository::object_cache_size_if_unset) to accelerate repeated commit lookups.
4444
#[cfg(feature = "revision")]
4545
pub fn merge_base(
@@ -60,47 +60,44 @@ impl crate::Repository {
6060
}
6161

6262
/// Obtain the best merge-base between commit `one` and `two`, or fail if there is none, providing a
63-
/// commit-graph `cache` to potentially greatly accelerate the operation.
63+
/// commit-graph `graph` to potentially greatly accelerate the operation by reusing graphs from previous runs.
6464
///
6565
/// # Performance
6666
/// Be sure to [set an object cache](crate::Repository::object_cache_size_if_unset) to accelerate repeated commit lookups.
6767
#[cfg(feature = "revision")]
68-
pub fn merge_base_with_cache(
68+
pub fn merge_base_with_graph(
6969
&self,
7070
one: impl Into<gix_hash::ObjectId>,
7171
two: impl Into<gix_hash::ObjectId>,
72-
cache: Option<&gix_commitgraph::Graph>,
73-
) -> Result<Id<'_>, super::merge_base_with_cache::Error> {
72+
graph: &mut gix_revwalk::Graph<'_, '_, gix_revwalk::graph::Commit<gix_revision::merge_base::Flags>>,
73+
) -> Result<Id<'_>, super::merge_base_with_graph::Error> {
7474
use crate::prelude::ObjectIdExt;
7575
let one = one.into();
7676
let two = two.into();
77-
let mut graph = self.revision_graph(cache);
78-
let bases = gix_revision::merge_base(one, &[two], &mut graph)?.ok_or(
79-
super::merge_base_with_cache::Error::NotFound {
77+
let bases =
78+
gix_revision::merge_base(one, &[two], graph)?.ok_or(super::merge_base_with_graph::Error::NotFound {
8079
first: one,
8180
second: two,
82-
},
83-
)?;
81+
})?;
8482
Ok(bases[0].attach(self))
8583
}
8684

8785
/// Obtain all merge-bases between commit `one` and `others`, or an empty list if there is none, providing a
88-
/// commit-graph `cache` to potentially greatly accelerate the operation.
86+
/// commit-graph `graph` to potentially greatly accelerate the operation.
8987
///
9088
/// # Performance
9189
/// Be sure to [set an object cache](crate::Repository::object_cache_size_if_unset) to accelerate repeated commit lookups.
9290
#[doc(alias = "merge_bases_many", alias = "git2")]
9391
#[cfg(feature = "revision")]
94-
pub fn merge_bases_many_with_cache(
92+
pub fn merge_bases_many_with_graph(
9593
&self,
9694
one: impl Into<gix_hash::ObjectId>,
9795
others: &[gix_hash::ObjectId],
98-
cache: Option<&gix_commitgraph::Graph>,
96+
graph: &mut gix_revwalk::Graph<'_, '_, gix_revwalk::graph::Commit<gix_revision::merge_base::Flags>>,
9997
) -> Result<Vec<Id<'_>>, gix_revision::merge_base::Error> {
10098
use crate::prelude::ObjectIdExt;
10199
let one = one.into();
102-
let mut graph = self.revision_graph(cache);
103-
Ok(gix_revision::merge_base(one, others, &mut graph)?
100+
Ok(gix_revision::merge_base(one, others, graph)?
104101
.unwrap_or_default()
105102
.into_iter()
106103
.map(|id| id.attach(self))

0 commit comments

Comments
 (0)