@@ -7,16 +7,55 @@ use gix_features::{progress::Progress, threading, zlib};
7
7
8
8
use crate :: {
9
9
cache:: delta:: {
10
- traverse:: {
11
- util:: { ItemSliceSend , Node } ,
12
- Context , Error ,
13
- } ,
10
+ traverse:: { util:: ItemSliceSend , Context , Error } ,
14
11
Item ,
15
12
} ,
16
13
data,
17
14
data:: EntryRange ,
18
15
} ;
19
16
17
+ /// An item returned by `iter_root_chunks`, allowing access to the `data` stored alongside nodes in a [`Tree`].
18
+ pub ( crate ) struct Node < ' a , T : Send > {
19
+ pub item : & ' a mut Item < T > ,
20
+ pub child_items : ItemSliceSend < ' a , Item < T > > ,
21
+ }
22
+
23
+ impl < ' a , T : Send > Node < ' a , T > {
24
+ /// Returns the offset into the pack at which the `Node`s data is located.
25
+ pub fn offset ( & self ) -> u64 {
26
+ self . item . offset
27
+ }
28
+
29
+ /// Returns the slice into the data pack at which the pack entry is located.
30
+ pub fn entry_slice ( & self ) -> crate :: data:: EntryRange {
31
+ self . item . offset ..self . item . next_offset
32
+ }
33
+
34
+ /// Returns the node data associated with this node.
35
+ pub fn data ( & mut self ) -> & mut T {
36
+ & mut self . item . data
37
+ }
38
+
39
+ /// Returns true if this node has children, e.g. is not a leaf in the tree.
40
+ pub fn has_children ( & self ) -> bool {
41
+ !self . item . children . is_empty ( )
42
+ }
43
+
44
+ /// Transform this `Node` into an iterator over its children.
45
+ ///
46
+ /// Children are `Node`s referring to pack entries whose base object is this pack entry.
47
+ pub fn into_child_iter ( self ) -> impl Iterator < Item = Node < ' a , T > > + ' a {
48
+ let children = self . child_items ;
49
+ // SAFETY: The index is a valid index into the children array.
50
+ // SAFETY: The resulting mutable pointer cannot be yielded by any other node.
51
+ #[ allow( unsafe_code) ]
52
+ self . item . children . iter ( ) . map ( move |& index| Node {
53
+ item : unsafe { children. get_mut ( index as usize ) } ,
54
+ child_items : children. clone ( ) ,
55
+ } )
56
+ }
57
+ }
58
+
20
59
pub ( crate ) struct State < ' items , F , MBFN , T : Send > {
21
60
pub delta_bytes : Vec < u8 > ,
22
61
pub fully_resolved_delta_bytes : Vec < u8 > ,
0 commit comments