@@ -31,6 +31,11 @@ pub struct PostOrderIterator {
31
31
/// to have only `Some` values.
32
32
type Leaves = Vec < Option < NamedLeaf > > ;
33
33
34
+ /// The nodes in the visit. We need to do a post-order visit, which starts from a single
35
+ /// `DescentRoot`, followed by N `Descents` where N is the deepest directory in the tree. On each
36
+ /// descent, we'll need to first schedule a `Post` (or `PostRoot`) followed the immediate children
37
+ /// of the node. Directories are rendered when all of their direct and indirect descendants have
38
+ /// been serialized into NamedLeafs.
34
39
#[ derive( Debug ) ]
35
40
enum Visited {
36
41
// handle root differently not to infect with the Option<String> and Option<usize>
@@ -39,13 +44,16 @@ enum Visited {
39
44
node : DirBuilder ,
40
45
name : String ,
41
46
depth : usize ,
47
+ /// The index in the parents `Leaves` accessible through `PostOrderIterator::persisted_cids`.
42
48
index : usize ,
43
49
} ,
44
50
Post {
45
51
parent_id : u64 ,
46
52
depth : usize ,
47
53
name : String ,
48
54
index : usize ,
55
+ /// Leaves will be stored directly in this field when there are no DirBuilder descendants,
56
+ /// in the `PostOrderIterator::persisted_cids` otherwise.
49
57
leaves : LeafStorage ,
50
58
} ,
51
59
PostRoot {
@@ -168,15 +176,10 @@ impl PostOrderIterator {
168
176
match visited {
169
177
Visited :: DescentRoot ( node) => {
170
178
let children = & mut self . reused_children ;
171
-
172
179
let leaves = partition_children_leaves ( depth, node. nodes . into_iter ( ) , children) ;
173
-
174
- // initial idea was to validate something with
175
-
176
180
let any_children = !children. is_empty ( ) ;
177
181
178
182
let leaves = if any_children {
179
- // we only need to put the leaves in there in the case of wrapping
180
183
self . persisted_cids . insert ( node. id , leaves) ;
181
184
LeafStorage :: from ( node. id )
182
185
} else {
@@ -193,14 +196,9 @@ impl PostOrderIterator {
193
196
index,
194
197
} => {
195
198
let children = & mut self . reused_children ;
196
-
197
199
let leaves = partition_children_leaves ( depth, node. nodes . into_iter ( ) , children) ;
198
-
199
200
let any_children = !children. is_empty ( ) ;
200
-
201
- // this would be none for only the single first node, however we know already
202
- // this is not the branch DescentRoot
203
- let parent_id = node. parent_id . expect ( "this is not root" ) ;
201
+ let parent_id = node. parent_id . expect ( "only roots parent_id is None" ) ;
204
202
205
203
let leaves = if any_children {
206
204
self . persisted_cids . insert ( node. id , leaves) ;
@@ -227,7 +225,6 @@ impl PostOrderIterator {
227
225
..
228
226
} => {
229
227
let leaves = leaves. into_inner ( & mut self . persisted_cids ) ;
230
-
231
228
let buffer = & mut self . block_buffer ;
232
229
233
230
let leaf = match Self :: render_directory (
@@ -450,7 +447,7 @@ impl LeafStorage {
450
447
Stashed ( id) => stash
451
448
. remove ( & id)
452
449
. ok_or ( id)
453
- . expect ( "could not find stashed leaves " ) ,
450
+ . expect ( "leaves are either stashed or direct, must able to find with id " ) ,
454
451
}
455
452
}
456
453
}
0 commit comments