1
- /// Returned by [`Tree::traverse()`]
2
- #[ derive( thiserror:: Error , Debug ) ]
3
- #[ allow( missing_docs) ]
4
- pub enum Error {
5
- #[ error( "Encountered unsupported command code: 0" ) ]
6
- UnsupportedCommandCode ,
7
- #[ error( "Delta copy from base: byte slices must match" ) ]
8
- DeltaCopyBaseSliceMismatch ,
9
- #[ error( "Delta copy data: byte slices must match" ) ]
10
- DeltaCopyDataSliceMismatch ,
1
+ ///
2
+ pub mod apply {
3
+ /// Returned when failing to apply deltas.
4
+ #[ derive( thiserror:: Error , Debug ) ]
5
+ #[ allow( missing_docs) ]
6
+ pub enum Error {
7
+ #[ error( "Encountered unsupported command code: 0" ) ]
8
+ UnsupportedCommandCode ,
9
+ #[ error( "Delta copy from base: byte slices must match" ) ]
10
+ DeltaCopyBaseSliceMismatch ,
11
+ #[ error( "Delta copy data: byte slices must match" ) ]
12
+ DeltaCopyDataSliceMismatch ,
13
+ }
11
14
}
12
15
13
16
/// Given the decompressed pack delta `d`, decode a size in bytes (either the base object size or the result object size)
14
17
/// Equivalent to [this canonical git function](https://github.com/git/git/blob/311531c9de557d25ac087c1637818bd2aad6eb3a/delta.h#L89)
15
- pub fn decode_header_size ( d : & [ u8 ] ) -> ( u64 , usize ) {
18
+ pub ( crate ) fn decode_header_size ( d : & [ u8 ] ) -> ( u64 , usize ) {
16
19
let mut i = 0 ;
17
20
let mut size = 0u64 ;
18
21
let mut consumed = 0 ;
@@ -27,7 +30,7 @@ pub fn decode_header_size(d: &[u8]) -> (u64, usize) {
27
30
( size, consumed)
28
31
}
29
32
30
- pub fn apply ( base : & [ u8 ] , mut target : & mut [ u8 ] , data : & [ u8 ] ) -> Result < ( ) , Error > {
33
+ pub ( crate ) fn apply ( base : & [ u8 ] , mut target : & mut [ u8 ] , data : & [ u8 ] ) -> Result < ( ) , apply :: Error > {
31
34
let mut i = 0 ;
32
35
while let Some ( cmd) = data. get ( i) {
33
36
i += 1 ;
@@ -67,12 +70,12 @@ pub fn apply(base: &[u8], mut target: &mut [u8], data: &[u8]) -> Result<(), Erro
67
70
}
68
71
let ofs = ofs as usize ;
69
72
std:: io:: Write :: write ( & mut target, & base[ ofs..ofs + size as usize ] )
70
- . map_err ( |_e| Error :: DeltaCopyBaseSliceMismatch ) ?;
73
+ . map_err ( |_e| apply :: Error :: DeltaCopyBaseSliceMismatch ) ?;
71
74
}
72
- 0 => return Err ( Error :: UnsupportedCommandCode ) ,
75
+ 0 => return Err ( apply :: Error :: UnsupportedCommandCode ) ,
73
76
size => {
74
77
std:: io:: Write :: write ( & mut target, & data[ i..i + * size as usize ] )
75
- . map_err ( |_e| Error :: DeltaCopyDataSliceMismatch ) ?;
78
+ . map_err ( |_e| apply :: Error :: DeltaCopyDataSliceMismatch ) ?;
76
79
i += * size as usize ;
77
80
}
78
81
}
0 commit comments