Skip to content

Commit

Permalink
Merge pull request GitoxideLabs#1716 from neithernut/traverse-topo-bu…
Browse files Browse the repository at this point in the history
…ilder-enhancements

Enhance builder-likeness of `commit::topo::Builder` in `gix-traverse`
  • Loading branch information
Byron authored Dec 9, 2024
2 parents 520c832 + 55eaf52 commit 67f20b1
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions gix-traverse/src/commit/topo/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,40 @@ where
tips: impl IntoIterator<Item = impl Into<ObjectId>>,
ends: Option<impl IntoIterator<Item = impl Into<ObjectId>>>,
) -> Self {
let tips = tips.into_iter().map(Into::into).collect::<Vec<_>>();
let ends = ends
.map(|e| e.into_iter().map(Into::into).collect::<Vec<_>>())
.unwrap_or_default();
Self::new(find).with_tips(tips).with_ends(ends.into_iter().flatten())
}

/// Create a new `Builder` for a [`Topo`] that reads commits from a
/// repository with `find`.
pub fn new(find: Find) -> Self {
Self {
commit_graph: Default::default(),
find,
sorting: Default::default(),
parents: Default::default(),
tips,
ends,
tips: Default::default(),
ends: Default::default(),
predicate: |_| true,
}
}

/// Add commits to start reading from.
///
/// The behavior is similar to specifying additional `ends` in `git rev-list --topo-order ^ends tips`.
pub fn with_tips(mut self, tips: impl IntoIterator<Item = impl Into<ObjectId>>) -> Self {
self.tips.extend(tips.into_iter().map(Into::into));
self
}

/// Add commits ending the traversal.
///
/// These commits themselves will not be read, i.e. the behavior is similar to specifying additional
/// `ends` in `git rev-list --topo-order ^ends tips`.
pub fn with_ends(mut self, ends: impl IntoIterator<Item = impl Into<ObjectId>>) -> Self {
self.ends.extend(ends.into_iter().map(Into::into));
self
}

/// Set a `predicate` to filter out revisions from the walk. Can be used to
/// implement e.g. filtering on paths or time. This does *not* exclude the
/// parent(s) of a revision that is excluded. Specify a revision as an 'end'
Expand Down

0 comments on commit 67f20b1

Please sign in to comment.