@@ -407,6 +407,11 @@ fn diff_file(
407
407
guess_content ( & rhs_bytes, rhs_path, binary_overrides) ,
408
408
) {
409
409
( ProbableFileKind :: Binary , _) | ( _, ProbableFileKind :: Binary ) => {
410
+ let has_byte_changes = if lhs_bytes == rhs_bytes {
411
+ None
412
+ } else {
413
+ Some ( ( lhs_bytes. len ( ) , rhs_bytes. len ( ) ) )
414
+ } ;
410
415
return DiffResult {
411
416
extra_info : renamed,
412
417
display_path : display_path. to_owned ( ) ,
@@ -416,7 +421,7 @@ fn diff_file(
416
421
lhs_positions : vec ! [ ] ,
417
422
rhs_positions : vec ! [ ] ,
418
423
hunks : vec ! [ ] ,
419
- has_byte_changes : lhs_bytes != rhs_bytes ,
424
+ has_byte_changes,
420
425
has_syntactic_changes : false ,
421
426
} ;
422
427
}
@@ -549,7 +554,11 @@ fn check_only_text(
549
554
lhs_src : & str ,
550
555
rhs_src : & str ,
551
556
) -> DiffResult {
552
- let has_changes = lhs_src != rhs_src;
557
+ let has_byte_changes = if lhs_src == rhs_src {
558
+ None
559
+ } else {
560
+ Some ( ( lhs_src. as_bytes ( ) . len ( ) , rhs_src. as_bytes ( ) . len ( ) ) )
561
+ } ;
553
562
554
563
DiffResult {
555
564
display_path : display_path. to_owned ( ) ,
@@ -560,8 +569,8 @@ fn check_only_text(
560
569
lhs_positions : vec ! [ ] ,
561
570
rhs_positions : vec ! [ ] ,
562
571
hunks : vec ! [ ] ,
563
- has_byte_changes : has_changes ,
564
- has_syntactic_changes : has_changes ,
572
+ has_byte_changes,
573
+ has_syntactic_changes : lhs_src != rhs_src ,
565
574
}
566
575
}
567
576
@@ -601,7 +610,7 @@ fn diff_file_content(
601
610
lhs_positions : vec ! [ ] ,
602
611
rhs_positions : vec ! [ ] ,
603
612
hunks : vec ! [ ] ,
604
- has_byte_changes : false ,
613
+ has_byte_changes : None ,
605
614
has_syntactic_changes : false ,
606
615
} ;
607
616
}
@@ -633,6 +642,13 @@ fn diff_file_content(
633
642
Ok ( ( lhs, rhs) ) => {
634
643
if diff_options. check_only {
635
644
let has_syntactic_changes = lhs != rhs;
645
+
646
+ let has_byte_changes = if lhs_src == rhs_src {
647
+ None
648
+ } else {
649
+ Some ( ( lhs_src. as_bytes ( ) . len ( ) , rhs_src. as_bytes ( ) . len ( ) ) )
650
+ } ;
651
+
636
652
return DiffResult {
637
653
extra_info,
638
654
display_path : display_path. to_owned ( ) ,
@@ -642,7 +658,7 @@ fn diff_file_content(
642
658
lhs_positions : vec ! [ ] ,
643
659
rhs_positions : vec ! [ ] ,
644
660
hunks : vec ! [ ] ,
645
- has_byte_changes : true ,
661
+ has_byte_changes,
646
662
has_syntactic_changes,
647
663
} ;
648
664
}
@@ -775,6 +791,12 @@ fn diff_file_content(
775
791
) ;
776
792
let has_syntactic_changes = !hunks. is_empty ( ) ;
777
793
794
+ let has_byte_changes = if lhs_src == rhs_src {
795
+ None
796
+ } else {
797
+ Some ( ( lhs_src. as_bytes ( ) . len ( ) , rhs_src. as_bytes ( ) . len ( ) ) )
798
+ } ;
799
+
778
800
DiffResult {
779
801
extra_info,
780
802
display_path : display_path. to_owned ( ) ,
@@ -784,7 +806,7 @@ fn diff_file_content(
784
806
lhs_positions,
785
807
rhs_positions,
786
808
hunks,
787
- has_byte_changes : true ,
809
+ has_byte_changes,
788
810
has_syntactic_changes,
789
811
}
790
812
}
@@ -923,7 +945,7 @@ fn print_diff_result(display_options: &DisplayOptions, summary: &DiffResult) {
923
945
}
924
946
}
925
947
( FileContent :: Binary , FileContent :: Binary ) => {
926
- if display_options. print_unchanged || summary. has_byte_changes {
948
+ if display_options. print_unchanged || summary. has_byte_changes . is_some ( ) {
927
949
println ! (
928
950
"{}" ,
929
951
display:: style:: header(
@@ -935,10 +957,17 @@ fn print_diff_result(display_options: &DisplayOptions, summary: &DiffResult) {
935
957
display_options
936
958
)
937
959
) ;
938
- if summary. has_byte_changes {
939
- println ! ( "Binary contents changed.\n " ) ;
940
- } else {
941
- println ! ( "No changes.\n " ) ;
960
+
961
+ match summary. has_byte_changes {
962
+ Some ( ( lhs_len, rhs_len) ) => {
963
+ let format_options = FormatSizeOptions :: from ( BINARY ) . decimal_places ( 1 ) ;
964
+ println ! (
965
+ "Binary contents changed (old: {}, new: {}).\n " ,
966
+ & format_size( lhs_len, format_options) ,
967
+ & format_size( rhs_len, format_options) ,
968
+ )
969
+ }
970
+ None => println ! ( "No changes.\n " ) ,
942
971
}
943
972
}
944
973
}
0 commit comments