@@ -239,7 +239,7 @@ fn raw_diff_to_file_diff<'a>(
239239 let mut patch = Patch :: from_buffers (
240240 & [ ] ,
241241 None ,
242- newfile_content. as_bytes ( ) ,
242+ newfile_content. as_slice ( ) ,
243243 Some ( & newfile_path) ,
244244 None ,
245245 ) ?;
@@ -283,14 +283,16 @@ fn raw_diff_to_file_diff<'a>(
283283 Ok ( res. into_inner ( ) )
284284}
285285
286- fn new_file_content ( path : & Path ) -> Option < String > {
286+ fn new_file_content ( path : & Path ) -> Option < Vec < u8 > > {
287287 if let Ok ( meta) = fs:: symlink_metadata ( path) {
288288 if meta. file_type ( ) . is_symlink ( ) {
289289 if let Ok ( path) = fs:: read_link ( path) {
290- return Some ( path. to_str ( ) ?. to_string ( ) ) ;
290+ return Some (
291+ path. to_str ( ) ?. to_string ( ) . as_bytes ( ) . into ( ) ,
292+ ) ;
291293 }
292294 } else if meta. file_type ( ) . is_file ( ) {
293- if let Ok ( content) = fs:: read_to_string ( path) {
295+ if let Ok ( content) = fs:: read ( path) {
294296 return Some ( content) ;
295297 }
296298 }
@@ -460,14 +462,20 @@ mod tests {
460462 }
461463
462464 #[ test]
463- fn test_diff_new_binary_file_using_invalid_utf8 ( ) -> Result < ( ) > {
465+ fn test_diff_delta_size ( ) -> Result < ( ) > {
464466 let file_path = Path :: new ( "bar" ) ;
465467 let ( _td, repo) = repo_init_empty ( ) . unwrap ( ) ;
466468 let root = repo. path ( ) . parent ( ) . unwrap ( ) ;
467469 let repo_path = root. as_os_str ( ) . to_str ( ) . unwrap ( ) ;
468470
471+ File :: create ( & root. join ( file_path) ) ?. write_all ( b"\x00 " ) ?;
472+
473+ stage_add_file ( repo_path, file_path) . unwrap ( ) ;
474+
475+ commit ( repo_path, "commit" ) . unwrap ( ) ;
476+
469477 File :: create ( & root. join ( file_path) ) ?
470- . write_all ( b"\xc3 \x28 " ) ?;
478+ . write_all ( b"\x00 \x02 " ) ?;
471479
472480 let diff = get_diff (
473481 repo_path,
@@ -476,26 +484,22 @@ mod tests {
476484 )
477485 . unwrap ( ) ;
478486
479- assert_eq ! ( diff. hunks. len( ) , 0 ) ;
487+ dbg ! ( & diff) ;
488+ assert_eq ! ( diff. sizes, ( 1 , 2 ) ) ;
489+ assert_eq ! ( diff. size_delta, 1 ) ;
480490
481491 Ok ( ( ) )
482492 }
483493
484494 #[ test]
485- fn test_diff_delta_size ( ) -> Result < ( ) > {
495+ fn test_binary_diff_delta_size_untracked ( ) -> Result < ( ) > {
486496 let file_path = Path :: new ( "bar" ) ;
487497 let ( _td, repo) = repo_init_empty ( ) . unwrap ( ) ;
488498 let root = repo. path ( ) . parent ( ) . unwrap ( ) ;
489499 let repo_path = root. as_os_str ( ) . to_str ( ) . unwrap ( ) ;
490500
491- File :: create ( & root. join ( file_path) ) ?. write_all ( b"\x00 " ) ?;
492-
493- stage_add_file ( repo_path, file_path) . unwrap ( ) ;
494-
495- commit ( repo_path, "commit" ) . unwrap ( ) ;
496-
497501 File :: create ( & root. join ( file_path) ) ?
498- . write_all ( b"\x00 \x02 " ) ?;
502+ . write_all ( b"\x00 \xc7 " ) ?;
499503
500504 let diff = get_diff (
501505 repo_path,
@@ -505,8 +509,8 @@ mod tests {
505509 . unwrap ( ) ;
506510
507511 dbg ! ( & diff) ;
508- assert_eq ! ( diff. sizes, ( 1 , 2 ) ) ;
509- assert_eq ! ( diff. size_delta, 1 ) ;
512+ assert_eq ! ( diff. sizes, ( 0 , 2 ) ) ;
513+ assert_eq ! ( diff. size_delta, 2 ) ;
510514
511515 Ok ( ( ) )
512516 }
0 commit comments