@@ -239,7 +239,7 @@ fn raw_diff_to_file_diff<'a>(
239
239
let mut patch = Patch :: from_buffers (
240
240
& [ ] ,
241
241
None ,
242
- newfile_content. as_bytes ( ) ,
242
+ newfile_content. as_slice ( ) ,
243
243
Some ( & newfile_path) ,
244
244
None ,
245
245
) ?;
@@ -283,14 +283,16 @@ fn raw_diff_to_file_diff<'a>(
283
283
Ok ( res. into_inner ( ) )
284
284
}
285
285
286
- fn new_file_content ( path : & Path ) -> Option < String > {
286
+ fn new_file_content ( path : & Path ) -> Option < Vec < u8 > > {
287
287
if let Ok ( meta) = fs:: symlink_metadata ( path) {
288
288
if meta. file_type ( ) . is_symlink ( ) {
289
289
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
+ ) ;
291
293
}
292
294
} 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) {
294
296
return Some ( content) ;
295
297
}
296
298
}
@@ -460,14 +462,20 @@ mod tests {
460
462
}
461
463
462
464
#[ test]
463
- fn test_diff_new_binary_file_using_invalid_utf8 ( ) -> Result < ( ) > {
465
+ fn test_diff_delta_size ( ) -> Result < ( ) > {
464
466
let file_path = Path :: new ( "bar" ) ;
465
467
let ( _td, repo) = repo_init_empty ( ) . unwrap ( ) ;
466
468
let root = repo. path ( ) . parent ( ) . unwrap ( ) ;
467
469
let repo_path = root. as_os_str ( ) . to_str ( ) . unwrap ( ) ;
468
470
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
+
469
477
File :: create ( & root. join ( file_path) ) ?
470
- . write_all ( b"\xc3 \x28 " ) ?;
478
+ . write_all ( b"\x00 \x02 " ) ?;
471
479
472
480
let diff = get_diff (
473
481
repo_path,
@@ -476,26 +484,22 @@ mod tests {
476
484
)
477
485
. unwrap ( ) ;
478
486
479
- assert_eq ! ( diff. hunks. len( ) , 0 ) ;
487
+ dbg ! ( & diff) ;
488
+ assert_eq ! ( diff. sizes, ( 1 , 2 ) ) ;
489
+ assert_eq ! ( diff. size_delta, 1 ) ;
480
490
481
491
Ok ( ( ) )
482
492
}
483
493
484
494
#[ test]
485
- fn test_diff_delta_size ( ) -> Result < ( ) > {
495
+ fn test_binary_diff_delta_size_untracked ( ) -> Result < ( ) > {
486
496
let file_path = Path :: new ( "bar" ) ;
487
497
let ( _td, repo) = repo_init_empty ( ) . unwrap ( ) ;
488
498
let root = repo. path ( ) . parent ( ) . unwrap ( ) ;
489
499
let repo_path = root. as_os_str ( ) . to_str ( ) . unwrap ( ) ;
490
500
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
-
497
501
File :: create ( & root. join ( file_path) ) ?
498
- . write_all ( b"\x00 \x02 " ) ?;
502
+ . write_all ( b"\x00 \xc7 " ) ?;
499
503
500
504
let diff = get_diff (
501
505
repo_path,
@@ -505,8 +509,8 @@ mod tests {
505
509
. unwrap ( ) ;
506
510
507
511
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 ) ;
510
514
511
515
Ok ( ( ) )
512
516
}
0 commit comments