Skip to content

Commit 67f20b1

Browse files
authored
Merge pull request #1716 from neithernut/traverse-topo-builder-enhancements
Enhance builder-likeness of `commit::topo::Builder` in `gix-traverse`
2 parents 520c832 + 55eaf52 commit 67f20b1

File tree

1 file changed

+24
-6
lines changed
  • gix-traverse/src/commit/topo

1 file changed

+24
-6
lines changed

Diff for: gix-traverse/src/commit/topo/init.rs

+24-6
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,40 @@ where
2828
tips: impl IntoIterator<Item = impl Into<ObjectId>>,
2929
ends: Option<impl IntoIterator<Item = impl Into<ObjectId>>>,
3030
) -> Self {
31-
let tips = tips.into_iter().map(Into::into).collect::<Vec<_>>();
32-
let ends = ends
33-
.map(|e| e.into_iter().map(Into::into).collect::<Vec<_>>())
34-
.unwrap_or_default();
31+
Self::new(find).with_tips(tips).with_ends(ends.into_iter().flatten())
32+
}
3533

34+
/// Create a new `Builder` for a [`Topo`] that reads commits from a
35+
/// repository with `find`.
36+
pub fn new(find: Find) -> Self {
3637
Self {
3738
commit_graph: Default::default(),
3839
find,
3940
sorting: Default::default(),
4041
parents: Default::default(),
41-
tips,
42-
ends,
42+
tips: Default::default(),
43+
ends: Default::default(),
4344
predicate: |_| true,
4445
}
4546
}
4647

48+
/// Add commits to start reading from.
49+
///
50+
/// The behavior is similar to specifying additional `ends` in `git rev-list --topo-order ^ends tips`.
51+
pub fn with_tips(mut self, tips: impl IntoIterator<Item = impl Into<ObjectId>>) -> Self {
52+
self.tips.extend(tips.into_iter().map(Into::into));
53+
self
54+
}
55+
56+
/// Add commits ending the traversal.
57+
///
58+
/// These commits themselves will not be read, i.e. the behavior is similar to specifying additional
59+
/// `ends` in `git rev-list --topo-order ^ends tips`.
60+
pub fn with_ends(mut self, ends: impl IntoIterator<Item = impl Into<ObjectId>>) -> Self {
61+
self.ends.extend(ends.into_iter().map(Into::into));
62+
self
63+
}
64+
4765
/// Set a `predicate` to filter out revisions from the walk. Can be used to
4866
/// implement e.g. filtering on paths or time. This does *not* exclude the
4967
/// parent(s) of a revision that is excluded. Specify a revision as an 'end'

0 commit comments

Comments
 (0)