@@ -31,7 +31,7 @@ pub enum Diff3OutputMode {
3131 EasyOnly , // -3: output only non-overlapping changes
3232}
3333
34- #[ derive( Clone , Debug ) ]
34+ #[ derive( Clone , Debug , Default ) ]
3535pub struct Diff3Params {
3636 pub executable : OsString ,
3737 pub mine : OsString ,
@@ -46,23 +46,7 @@ pub struct Diff3Params {
4646 pub compat_i : bool , // -i option for ed script compatibility
4747}
4848
49- impl Default for Diff3Params {
50- fn default ( ) -> Self {
51- Self {
52- executable : OsString :: default ( ) ,
53- mine : OsString :: default ( ) ,
54- older : OsString :: default ( ) ,
55- yours : OsString :: default ( ) ,
56- format : Diff3Format :: default ( ) ,
57- output_mode : Diff3OutputMode :: default ( ) ,
58- text : false ,
59- labels : [ None , None , None ] ,
60- strip_trailing_cr : false ,
61- initial_tab : false ,
62- compat_i : false ,
63- }
64- }
65- }
49+ // Default is derived above
6650
6751pub fn parse_params < I : Iterator < Item = OsString > > ( mut opts : Peekable < I > ) -> Result < Diff3Params , String > {
6852 let Some ( executable) = opts. next ( ) else {
@@ -78,6 +62,7 @@ pub fn parse_params<I: Iterator<Item = OsString>>(mut opts: Peekable<I>) -> Resu
7862 let mut yours = None ;
7963 let mut label_count = 0 ;
8064
65+ #[ allow( clippy:: while_let_on_iterator) ]
8166 while let Some ( param) = opts. next ( ) {
8267 let param_str = param. to_string_lossy ( ) ;
8368
@@ -169,11 +154,11 @@ pub fn parse_params<I: Iterator<Item = OsString>>(mut opts: Peekable<I>) -> Resu
169154 label_count += 1 ;
170155 continue ;
171156 }
172- if param_str. starts_with ( "--label=" ) {
157+ if let Some ( stripped ) = param_str. strip_prefix ( "--label=" ) {
173158 if label_count >= 3 {
174159 return Err ( "Too many labels" . to_string ( ) ) ;
175160 }
176- let label = param_str [ 8 .. ] . to_string ( ) ;
161+ let label = stripped . to_string ( ) ;
177162 params. labels [ label_count] = Some ( label) ;
178163 label_count += 1 ;
179164 continue ;
@@ -209,7 +194,7 @@ pub fn parse_params<I: Iterator<Item = OsString>>(mut opts: Peekable<I>) -> Resu
209194 }
210195
211196 // Collect remaining arguments
212- while let Some ( param) = opts. next ( ) {
197+ for param in opts {
213198 if mine. is_none ( ) {
214199 mine = Some ( param) ;
215200 } else if older. is_none ( ) {
@@ -609,9 +594,9 @@ fn build_conflict_regions(
609594 }
610595 } else if has_mine_changes || has_yours_changes {
611596 // Only one side changed - check if it differs from older
612- if has_mine_changes && mine_lines. len ( ) != older_lines. len ( ) {
613- ConflictType :: EasyConflict
614- } else if has_yours_changes && yours_lines . len ( ) != older_lines . len ( ) {
597+ if ( has_mine_changes && mine_lines. len ( ) != older_lines. len ( ) )
598+ || ( has_yours_changes && yours_lines . len ( ) != older_lines . len ( ) )
599+ {
615600 ConflictType :: EasyConflict
616601 } else {
617602 ConflictType :: NoConflict
@@ -622,7 +607,7 @@ fn build_conflict_regions(
622607 } ;
623608
624609 // Create a single region representing the whole file
625- if mine_lines. len ( ) > 0 || older_lines. len ( ) > 0 || yours_lines. len ( ) > 0 {
610+ if ! mine_lines. is_empty ( ) || ! older_lines. is_empty ( ) || ! yours_lines. is_empty ( ) {
626611 regions. push ( Diff3Region {
627612 mine_start : 0 ,
628613 mine_count : mine_lines. len ( ) ,
@@ -691,6 +676,7 @@ fn should_include_region(region: &Diff3Region, output_mode: Diff3OutputMode) ->
691676 }
692677}
693678
679+ #[ allow( clippy:: too_many_arguments) ]
694680fn generate_normal_output (
695681 _diff_mine_older : & [ diff:: Result < & & [ u8 ] > ] ,
696682 _diff_older_yours : & [ diff:: Result < & & [ u8 ] > ] ,
@@ -706,35 +692,21 @@ fn generate_normal_output(
706692 // Generate diff3 normal format output
707693 // For now, generate simple diff output between mine and yours
708694 for line_num in 0 ..mine_lines. len ( ) . max ( yours_lines. len ( ) ) {
709- if line_num < mine_lines. len ( ) && line_num < yours_lines. len ( ) {
710- if mine_lines[ line_num] != yours_lines[ line_num] {
711- writeln ! (
712- & mut output,
713- "{}c{}" ,
714- line_num + 1 ,
715- line_num + 1
716- )
717- . unwrap ( ) ;
718- writeln ! (
719- & mut output,
720- "< {}" ,
721- String :: from_utf8_lossy( mine_lines[ line_num] )
722- )
723- . unwrap ( ) ;
724- writeln ! ( & mut output, "---" ) . unwrap ( ) ;
725- writeln ! (
726- & mut output,
727- "> {}" ,
728- String :: from_utf8_lossy( yours_lines[ line_num] )
729- )
730- . unwrap ( ) ;
731- }
695+ if line_num < mine_lines. len ( )
696+ && line_num < yours_lines. len ( )
697+ && mine_lines[ line_num] != yours_lines[ line_num]
698+ {
699+ writeln ! ( & mut output, "{}c{}" , line_num + 1 , line_num + 1 ) . unwrap ( ) ;
700+ writeln ! ( & mut output, "< {}" , String :: from_utf8_lossy( mine_lines[ line_num] ) ) . unwrap ( ) ;
701+ writeln ! ( & mut output, "---" ) . unwrap ( ) ;
702+ writeln ! ( & mut output, "> {}" , String :: from_utf8_lossy( yours_lines[ line_num] ) ) . unwrap ( ) ;
732703 }
733704 }
734705
735706 output
736707}
737708
709+ #[ allow( clippy:: too_many_arguments) ]
738710fn generate_merged_output (
739711 _diff_mine_older : & [ diff:: Result < & & [ u8 ] > ] ,
740712 _diff_older_yours : & [ diff:: Result < & & [ u8 ] > ] ,
@@ -763,7 +735,7 @@ fn generate_merged_output(
763735
764736 // If filtering, check if this region should be included
765737 let region = regions. first ( ) ;
766- if should_filter && region. map_or ( false , |r| !should_include_region ( r, params. output_mode ) ) {
738+ if should_filter && region. is_some_and ( |r| !should_include_region ( r, params. output_mode ) ) {
767739 // Output nothing if region doesn't match filter
768740 return output;
769741 }
@@ -782,12 +754,12 @@ fn generate_merged_output(
782754 . unwrap ( ) ;
783755 } else {
784756 // Only output conflict if it matches the filter
785- if !should_filter || region. map_or ( true , |r| should_include_region ( r, params. output_mode ) ) {
757+ if !should_filter || region. is_none_or ( |r| should_include_region ( r, params. output_mode ) ) {
786758 // Conflict with optional markers based on output mode
787759 match params. output_mode {
788760 Diff3OutputMode :: OverlapOnlyMarked => {
789761 // Show conflict markers for overlapping conflicts
790- if region. map_or ( false , |r| r. conflict == ConflictType :: OverlappingConflict ) {
762+ if region. is_some_and ( |r| r. conflict == ConflictType :: OverlappingConflict ) {
791763 writeln ! ( & mut output, "<<<<<<< {}" , mine_label) . unwrap ( ) ;
792764 writeln ! (
793765 & mut output,
@@ -850,6 +822,7 @@ fn generate_merged_output(
850822 output
851823}
852824
825+ #[ allow( clippy:: too_many_arguments) ]
853826fn generate_ed_script (
854827 _diff_mine_older : & [ diff:: Result < & & [ u8 ] > ] ,
855828 _diff_older_yours : & [ diff:: Result < & & [ u8 ] > ] ,
@@ -878,7 +851,7 @@ fn generate_ed_script(
878851
879852 // If filtering, check if this region should be included
880853 let region = regions. first ( ) ;
881- if should_filter && region. map_or ( false , |r| !should_include_region ( r, params. output_mode ) ) {
854+ if should_filter && region. is_some_and ( |r| !should_include_region ( r, params. output_mode ) ) {
882855 // Output nothing if region doesn't match filter
883856 return output;
884857 }
@@ -893,7 +866,7 @@ fn generate_ed_script(
893866 ( Some ( mine) , Some ( yours) ) => {
894867 if mine != yours {
895868 // Only output if it matches the filter
896- if !should_filter || region. map_or ( true , |r| should_include_region ( r, params. output_mode ) ) {
869+ if !should_filter || region. is_none_or ( |r| should_include_region ( r, params. output_mode ) ) {
897870 // Change command
898871 writeln ! ( & mut output, "{}c" , line_num + 1 ) . unwrap ( ) ;
899872 writeln ! (
@@ -922,13 +895,13 @@ fn generate_ed_script(
922895 }
923896 ( Some ( _) , None ) => {
924897 // Delete command (only if not filtering or filter passes)
925- if !should_filter || region. map_or ( true , |r| should_include_region ( r, params. output_mode ) ) {
898+ if !should_filter || region. is_none_or ( |r| should_include_region ( r, params. output_mode ) ) {
926899 writeln ! ( & mut output, "{}d" , line_num + 1 ) . unwrap ( ) ;
927900 }
928901 }
929902 ( None , Some ( yours) ) => {
930903 // Add command (only if not filtering or filter passes)
931- if !should_filter || region. map_or ( true , |r| should_include_region ( r, params. output_mode ) ) {
904+ if !should_filter || region. is_none_or ( |r| should_include_region ( r, params. output_mode ) ) {
932905 writeln ! ( & mut output, "{}a" , line_num) . unwrap ( ) ;
933906 writeln ! (
934907 & mut output,
@@ -1012,8 +985,6 @@ pub fn main(opts: Peekable<ArgsOs>) -> ExitCode {
1012985
1013986 if has_conflicts {
1014987 ExitCode :: from ( 1 )
1015- } else if result. is_empty ( ) {
1016- ExitCode :: SUCCESS
1017988 } else {
1018989 ExitCode :: SUCCESS
1019990 }
0 commit comments