Skip to content

Commit a19efb5

Browse files
committed
feat: add Tree::depthfirst() with a delegate.
This allows a depth-first traversal with a delegate.
1 parent 698a290 commit a19efb5

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

gix/src/object/tree/traverse.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ impl<'repo> Tree<'repo> {
1515
pub struct Platform<'a, 'repo> {
1616
root: &'a Tree<'repo>,
1717
/// Provides easy access to presets for common breadth-first traversal.
18+
// TODO: remove this - it's a bit too much of a fixed function, or go all in once it's clear it's needed,
19+
// but probably with depth-first.
1820
pub breadthfirst: BreadthFirstPresets<'a, 'repo>,
1921
}
2022

@@ -38,12 +40,12 @@ impl BreadthFirstPresets<'_, '_> {
3840
}
3941

4042
impl Platform<'_, '_> {
41-
/// Start a breadth-first, recursive traversal using `delegate`, for which a [`Recorder`][gix_traverse::tree::Recorder] can be used to get started.
43+
/// Start a breadth-first, recursive traversal using `delegate`, for which a [`Recorder`](gix_traverse::tree::Recorder) can be used to get started.
4244
///
4345
/// # Note
4446
///
45-
/// - Results are returned in sort order according to tree-entry sorting rules, one level at a time.
46-
/// - for obtaining the direct children of the tree, use [.iter()][crate::Tree::iter()] instead.
47+
/// - Results are returned in sort order as per tree-sorting rules, files first, then directories, one level at a time.
48+
/// - for obtaining the direct children of the tree, use [Tree::iter()] instead.
4749
pub fn breadthfirst<V>(&self, delegate: &mut V) -> Result<(), gix_traverse::tree::breadthfirst::Error>
4850
where
4951
V: gix_traverse::tree::Visit,
@@ -52,4 +54,17 @@ impl Platform<'_, '_> {
5254
let state = gix_traverse::tree::breadthfirst::State::default();
5355
gix_traverse::tree::breadthfirst(root, state, &self.root.repo.objects, delegate)
5456
}
57+
58+
/// Start a depth-first, recursive traversal using `delegate`, for which a [`Recorder`](gix_traverse::tree::Recorder) can be used to get started.
59+
///
60+
/// # Note
61+
///
62+
/// For obtaining the direct children of the tree, use [Tree::iter()] instead.
63+
pub fn depthfirst<V>(&self, delegate: &mut V) -> Result<(), gix_traverse::tree::breadthfirst::Error>
64+
where
65+
V: gix_traverse::tree::Visit,
66+
{
67+
let state = gix_traverse::tree::depthfirst::State::default();
68+
gix_traverse::tree::depthfirst(self.root.id, state, &self.root.repo.objects, delegate)
69+
}
5570
}

0 commit comments

Comments
 (0)