@@ -25,6 +25,7 @@ pub struct Params {
2525 pub to : OsString ,
2626 pub format : Format ,
2727 pub context_count : usize ,
28+ pub report_identical_files : bool ,
2829}
2930
3031pub fn parse_params < I : IntoIterator < Item = OsString > > ( opts : I ) -> Result < Params , String > {
@@ -38,6 +39,7 @@ pub fn parse_params<I: IntoIterator<Item = OsString>>(opts: I) -> Result<Params,
3839 let mut to = None ;
3940 let mut format = None ;
4041 let mut context_count = 3 ;
42+ let mut report_identical_files = false ;
4143 while let Some ( param) = opts. next ( ) {
4244 if param == "--" {
4345 break ;
@@ -52,6 +54,10 @@ pub fn parse_params<I: IntoIterator<Item = OsString>>(opts: I) -> Result<Params,
5254 }
5355 continue ;
5456 }
57+ if param == "-s" || param == "--report-identical-files" {
58+ report_identical_files = true ;
59+ continue ;
60+ }
5561 let p = osstr_bytes ( & param) ;
5662 if p. first ( ) == Some ( & b'-' ) && p. get ( 1 ) != Some ( & b'-' ) {
5763 let mut bit = p[ 1 ..] . iter ( ) . copied ( ) . peekable ( ) ;
@@ -133,6 +139,7 @@ pub fn parse_params<I: IntoIterator<Item = OsString>>(opts: I) -> Result<Params,
133139 to,
134140 format,
135141 context_count,
142+ report_identical_files,
136143 } )
137144}
138145
@@ -150,6 +157,7 @@ mod tests {
150157 to: os( "bar" ) ,
151158 format: Format :: Normal ,
152159 context_count: 3 ,
160+ report_identical_files: false ,
153161 } ) ,
154162 parse_params( [ os( "diff" ) , os( "foo" ) , os( "bar" ) ] . iter( ) . cloned( ) )
155163 ) ;
@@ -162,6 +170,7 @@ mod tests {
162170 to: os( "bar" ) ,
163171 format: Format :: Ed ,
164172 context_count: 3 ,
173+ report_identical_files: false ,
165174 } ) ,
166175 parse_params( [ os( "diff" ) , os( "-e" ) , os( "foo" ) , os( "bar" ) ] . iter( ) . cloned( ) )
167176 ) ;
@@ -174,6 +183,7 @@ mod tests {
174183 to: os( "bar" ) ,
175184 format: Format :: Unified ,
176185 context_count: 54 ,
186+ report_identical_files: false ,
177187 } ) ,
178188 parse_params(
179189 [ os( "diff" ) , os( "-u54" ) , os( "foo" ) , os( "bar" ) ]
@@ -187,6 +197,7 @@ mod tests {
187197 to: os( "bar" ) ,
188198 format: Format :: Unified ,
189199 context_count: 54 ,
200+ report_identical_files: false ,
190201 } ) ,
191202 parse_params(
192203 [ os( "diff" ) , os( "-U54" ) , os( "foo" ) , os( "bar" ) ]
@@ -200,6 +211,7 @@ mod tests {
200211 to: os( "bar" ) ,
201212 format: Format :: Unified ,
202213 context_count: 54 ,
214+ report_identical_files: false ,
203215 } ) ,
204216 parse_params(
205217 [ os( "diff" ) , os( "-U" ) , os( "54" ) , os( "foo" ) , os( "bar" ) ]
@@ -213,6 +225,7 @@ mod tests {
213225 to: os( "bar" ) ,
214226 format: Format :: Context ,
215227 context_count: 54 ,
228+ report_identical_files: false ,
216229 } ) ,
217230 parse_params(
218231 [ os( "diff" ) , os( "-c54" ) , os( "foo" ) , os( "bar" ) ]
@@ -222,13 +235,56 @@ mod tests {
222235 ) ;
223236 }
224237 #[ test]
238+ fn report_identical_files ( ) {
239+ assert_eq ! (
240+ Ok ( Params {
241+ from: os( "foo" ) ,
242+ to: os( "bar" ) ,
243+ format: Format :: Normal ,
244+ context_count: 3 ,
245+ report_identical_files: false ,
246+ } ) ,
247+ parse_params( [ os( "diff" ) , os( "foo" ) , os( "bar" ) ] . iter( ) . cloned( ) )
248+ ) ;
249+ assert_eq ! (
250+ Ok ( Params {
251+ from: os( "foo" ) ,
252+ to: os( "bar" ) ,
253+ format: Format :: Normal ,
254+ context_count: 3 ,
255+ report_identical_files: true ,
256+ } ) ,
257+ parse_params( [ os( "diff" ) , os( "-s" ) , os( "foo" ) , os( "bar" ) ] . iter( ) . cloned( ) )
258+ ) ;
259+ assert_eq ! (
260+ Ok ( Params {
261+ from: os( "foo" ) ,
262+ to: os( "bar" ) ,
263+ format: Format :: Normal ,
264+ context_count: 3 ,
265+ report_identical_files: true ,
266+ } ) ,
267+ parse_params(
268+ [
269+ os( "diff" ) ,
270+ os( "--report-identical-files" ) ,
271+ os( "foo" ) ,
272+ os( "bar" ) ,
273+ ]
274+ . iter( )
275+ . cloned( )
276+ )
277+ ) ;
278+ }
279+ #[ test]
225280 fn double_dash ( ) {
226281 assert_eq ! (
227282 Ok ( Params {
228283 from: os( "-g" ) ,
229284 to: os( "-h" ) ,
230285 format: Format :: Normal ,
231286 context_count: 3 ,
287+ report_identical_files: false ,
232288 } ) ,
233289 parse_params( [ os( "diff" ) , os( "--" ) , os( "-g" ) , os( "-h" ) ] . iter( ) . cloned( ) )
234290 ) ;
0 commit comments