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+ }
1114}
1215
1316/// Given the decompressed pack delta `d`, decode a size in bytes (either the base object size or the result object size)
1417/// 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 ) {
1619 let mut i = 0 ;
1720 let mut size = 0u64 ;
1821 let mut consumed = 0 ;
@@ -27,7 +30,7 @@ pub fn decode_header_size(d: &[u8]) -> (u64, usize) {
2730 ( size, consumed)
2831}
2932
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 > {
3134 let mut i = 0 ;
3235 while let Some ( cmd) = data. get ( i) {
3336 i += 1 ;
@@ -67,12 +70,12 @@ pub fn apply(base: &[u8], mut target: &mut [u8], data: &[u8]) -> Result<(), Erro
6770 }
6871 let ofs = ofs as usize ;
6972 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 ) ?;
7174 }
72- 0 => return Err ( Error :: UnsupportedCommandCode ) ,
75+ 0 => return Err ( apply :: Error :: UnsupportedCommandCode ) ,
7376 size => {
7477 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 ) ?;
7679 i += * size as usize ;
7780 }
7881 }
0 commit comments