1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use git_odb::FindExt;
use crate::Tree;
impl<'repo> Tree<'repo> {
pub fn traverse(&self) -> Platform<'_, 'repo> {
Platform {
root: self,
breadthfirst: BreadthFirstPresets { root: self },
}
}
}
pub struct Platform<'a, 'repo> {
root: &'a Tree<'repo>,
pub breadthfirst: BreadthFirstPresets<'a, 'repo>,
}
#[derive(Copy, Clone)]
pub struct BreadthFirstPresets<'a, 'repo> {
root: &'a Tree<'repo>,
}
impl<'a, 'repo> BreadthFirstPresets<'a, 'repo> {
pub fn files(&self) -> Result<Vec<git_traverse::tree::recorder::Entry>, git_traverse::tree::breadthfirst::Error> {
let mut recorder = git_traverse::tree::Recorder::default();
Platform {
root: self.root,
breadthfirst: *self,
}
.breadthfirst(&mut recorder)?;
Ok(recorder.records)
}
}
impl<'a, 'repo> Platform<'a, 'repo> {
pub fn breadthfirst<V>(&self, delegate: &mut V) -> Result<(), git_traverse::tree::breadthfirst::Error>
where
V: git_traverse::tree::Visit,
{
let root = git_object::TreeRefIter::from_bytes(&self.root.data);
let state = git_traverse::tree::breadthfirst::State::default();
git_traverse::tree::breadthfirst(
root,
state,
|oid, buf| self.root.repo.objects.find_tree_iter(oid, buf).ok(),
delegate,
)
}
}