@@ -25,6 +25,7 @@ pub struct Params {
25
25
pub to : OsString ,
26
26
pub format : Format ,
27
27
pub context_count : usize ,
28
+ pub report_identical_files : bool ,
28
29
}
29
30
30
31
pub 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,
38
39
let mut to = None ;
39
40
let mut format = None ;
40
41
let mut context_count = 3 ;
42
+ let mut report_identical_files = false ;
41
43
while let Some ( param) = opts. next ( ) {
42
44
if param == "--" {
43
45
break ;
@@ -52,6 +54,10 @@ pub fn parse_params<I: IntoIterator<Item = OsString>>(opts: I) -> Result<Params,
52
54
}
53
55
continue ;
54
56
}
57
+ if param == "-s" || param == "--report-identical-files" {
58
+ report_identical_files = true ;
59
+ continue ;
60
+ }
55
61
let p = osstr_bytes ( & param) ;
56
62
if p. first ( ) == Some ( & b'-' ) && p. get ( 1 ) != Some ( & b'-' ) {
57
63
let mut bit = p[ 1 ..] . iter ( ) . copied ( ) . peekable ( ) ;
@@ -133,6 +139,7 @@ pub fn parse_params<I: IntoIterator<Item = OsString>>(opts: I) -> Result<Params,
133
139
to,
134
140
format,
135
141
context_count,
142
+ report_identical_files,
136
143
} )
137
144
}
138
145
@@ -150,6 +157,7 @@ mod tests {
150
157
to: os( "bar" ) ,
151
158
format: Format :: Normal ,
152
159
context_count: 3 ,
160
+ report_identical_files: false ,
153
161
} ) ,
154
162
parse_params( [ os( "diff" ) , os( "foo" ) , os( "bar" ) ] . iter( ) . cloned( ) )
155
163
) ;
@@ -162,6 +170,7 @@ mod tests {
162
170
to: os( "bar" ) ,
163
171
format: Format :: Ed ,
164
172
context_count: 3 ,
173
+ report_identical_files: false ,
165
174
} ) ,
166
175
parse_params( [ os( "diff" ) , os( "-e" ) , os( "foo" ) , os( "bar" ) ] . iter( ) . cloned( ) )
167
176
) ;
@@ -174,6 +183,7 @@ mod tests {
174
183
to: os( "bar" ) ,
175
184
format: Format :: Unified ,
176
185
context_count: 54 ,
186
+ report_identical_files: false ,
177
187
} ) ,
178
188
parse_params(
179
189
[ os( "diff" ) , os( "-u54" ) , os( "foo" ) , os( "bar" ) ]
@@ -187,6 +197,7 @@ mod tests {
187
197
to: os( "bar" ) ,
188
198
format: Format :: Unified ,
189
199
context_count: 54 ,
200
+ report_identical_files: false ,
190
201
} ) ,
191
202
parse_params(
192
203
[ os( "diff" ) , os( "-U54" ) , os( "foo" ) , os( "bar" ) ]
@@ -200,6 +211,7 @@ mod tests {
200
211
to: os( "bar" ) ,
201
212
format: Format :: Unified ,
202
213
context_count: 54 ,
214
+ report_identical_files: false ,
203
215
} ) ,
204
216
parse_params(
205
217
[ os( "diff" ) , os( "-U" ) , os( "54" ) , os( "foo" ) , os( "bar" ) ]
@@ -213,6 +225,7 @@ mod tests {
213
225
to: os( "bar" ) ,
214
226
format: Format :: Context ,
215
227
context_count: 54 ,
228
+ report_identical_files: false ,
216
229
} ) ,
217
230
parse_params(
218
231
[ os( "diff" ) , os( "-c54" ) , os( "foo" ) , os( "bar" ) ]
@@ -222,13 +235,56 @@ mod tests {
222
235
) ;
223
236
}
224
237
#[ 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]
225
280
fn double_dash ( ) {
226
281
assert_eq ! (
227
282
Ok ( Params {
228
283
from: os( "-g" ) ,
229
284
to: os( "-h" ) ,
230
285
format: Format :: Normal ,
231
286
context_count: 3 ,
287
+ report_identical_files: false ,
232
288
} ) ,
233
289
parse_params( [ os( "diff" ) , os( "--" ) , os( "-g" ) , os( "-h" ) ] . iter( ) . cloned( ) )
234
290
) ;
0 commit comments