Skip to content

Commit

Permalink
feat: add topo::Builder::new fn for creating a bare builder
Browse files Browse the repository at this point in the history
Previously, the only way to create a `Builder` would be via
`Builder::from_iters`. That fn takes as arguments both the tips and
ends, and used to be the only possibility for specifying either of them
during the building process. However, in order to enhance the builder-
likeness of `Builder`, we recently introduced fns `with_tips` and
`with_ends` for adding additional tips and ends.

With those fns, the only component which needs to be supplied up-front
is `find`. Users can specify and empty `Iterator` and `None` for `tips`
and `ends` respectively when calling `Builder::from_iters` and add
additional tips and ends at their leisure, without the need to chain
`Iterator`s or collecting them in some external data structure.

Now, calling `Builder::from_iters` with a empty lists for tips and ends
is a bit awkward. Thus, we provide a new method for creating a bare
`Builder`.
  • Loading branch information
neithernut committed Dec 9, 2024
1 parent a7a8d7c commit 59148a2
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions gix-traverse/src/commit/topo/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ where
}
}

/// 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: 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 {
Expand Down

0 comments on commit 59148a2

Please sign in to comment.