File tree Expand file tree Collapse file tree 2 files changed +36
-5
lines changed Expand file tree Collapse file tree 2 files changed +36
-5
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,11 @@ mod error {
15
15
MandatoryUnimplemented ( signature: extension:: Signature ) {
16
16
display( "Encountered mandatory extension '{}' which isn't implemented yet" , String :: from_utf8_lossy( signature) )
17
17
}
18
+ Link ( err: extension:: link:: decode:: Error ) {
19
+ display( "Could not parse mandatory link extension" )
20
+ source( err)
21
+ from( )
22
+ }
18
23
}
19
24
}
20
25
}
@@ -35,7 +40,7 @@ pub fn all(maybe_beginning_of_extensions: &[u8], object_hash: git_hash::Kind) ->
35
40
extension:: end_of_index_entry:: SIGNATURE => { } // skip already done
36
41
extension:: index_entry_offset_table:: SIGNATURE => { } // not relevant/obtained already
37
42
mandatory if mandatory[ 0 ] . is_ascii_lowercase ( ) => match mandatory {
38
- extension:: link:: SIGNATURE => ext. link = extension:: link:: decode ( ext_data, object_hash) ,
43
+ extension:: link:: SIGNATURE => ext. link = extension:: link:: decode ( ext_data, object_hash) ? . into ( ) ,
39
44
unknown => return Err ( Error :: MandatoryUnimplemented ( unknown) ) ,
40
45
} ,
41
46
_unknown => { } // skip unknown extensions, too
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ pub struct Tree {
21
21
}
22
22
23
23
pub struct Link {
24
- shared_index_checksum : git_hash:: ObjectId ,
24
+ pub shared_index_checksum : git_hash:: ObjectId ,
25
25
}
26
26
27
27
mod iter;
@@ -34,11 +34,37 @@ pub(crate) mod end_of_index_entry;
34
34
35
35
pub ( crate ) mod index_entry_offset_table;
36
36
37
- pub ( crate ) mod link {
37
+ pub mod link {
38
38
use crate :: extension:: { Link , Signature } ;
39
+ use crate :: util:: split_at_pos;
40
+
39
41
pub const SIGNATURE : Signature = * b"link" ;
40
42
41
- pub fn decode ( _data : & [ u8 ] , _object_hash : git_hash:: Kind ) -> Option < Link > {
42
- todo ! ( "decode link" )
43
+ pub mod decode {
44
+ use quick_error:: quick_error;
45
+
46
+ quick_error ! {
47
+ #[ derive( Debug ) ]
48
+ pub enum Error {
49
+ Corrupt ( message: & ' static str ) {
50
+ display( "{}" , message)
51
+ }
52
+ }
53
+ }
54
+ }
55
+
56
+ pub fn decode ( data : & [ u8 ] , object_hash : git_hash:: Kind ) -> Result < Link , decode:: Error > {
57
+ let ( id, data) = split_at_pos ( data, object_hash. len_in_bytes ( ) )
58
+ . ok_or ( decode:: Error :: Corrupt (
59
+ "link extension too short to read share index checksum" ,
60
+ ) )
61
+ . map ( |( id, d) | ( git_hash:: ObjectId :: from ( id) , d) ) ?;
62
+
63
+ if data. is_empty ( ) {
64
+ return Ok ( Link {
65
+ shared_index_checksum : id,
66
+ } ) ;
67
+ }
68
+ todo ! ( "decode link bitmaps" )
43
69
}
44
70
}
You can’t perform that action at this time.
0 commit comments