@@ -190,13 +190,31 @@ static unsigned int contains(struct diff_filespec *one,
190
190
return cnt ;
191
191
}
192
192
193
+ static int has_changes (struct diff_filepair * p , const char * needle ,
194
+ unsigned long len , regex_t * regexp , kwset_t kws )
195
+ {
196
+ if (!DIFF_FILE_VALID (p -> one )) {
197
+ if (!DIFF_FILE_VALID (p -> two ))
198
+ return 0 ; /* ignore unmerged */
199
+ /* created */
200
+ return contains (p -> two , needle , len , regexp , kws ) != 0 ;
201
+ }
202
+ if (!DIFF_FILE_VALID (p -> two ))
203
+ return contains (p -> one , needle , len , regexp , kws ) != 0 ;
204
+ if (!diff_unmodified_pair (p )) {
205
+ return contains (p -> one , needle , len , regexp , kws ) !=
206
+ contains (p -> two , needle , len , regexp , kws );
207
+ }
208
+ return 0 ;
209
+ }
210
+
193
211
static void diffcore_pickaxe_count (struct diff_options * o )
194
212
{
195
213
const char * needle = o -> pickaxe ;
196
214
int opts = o -> pickaxe_opts ;
197
215
struct diff_queue_struct * q = & diff_queued_diff ;
198
216
unsigned long len = strlen (needle );
199
- int i , has_changes ;
217
+ int i ;
200
218
regex_t regex , * regexp = NULL ;
201
219
kwset_t kws = NULL ;
202
220
struct diff_queue_struct outq ;
@@ -223,22 +241,7 @@ static void diffcore_pickaxe_count(struct diff_options *o)
223
241
/* Showing the whole changeset if needle exists */
224
242
for (i = 0 ; i < q -> nr ; i ++ ) {
225
243
struct diff_filepair * p = q -> queue [i ];
226
- if (!DIFF_FILE_VALID (p -> one )) {
227
- if (!DIFF_FILE_VALID (p -> two ))
228
- continue ; /* ignore unmerged */
229
- /* created */
230
- if (contains (p -> two , needle , len , regexp , kws ))
231
- has_changes ++ ;
232
- }
233
- else if (!DIFF_FILE_VALID (p -> two )) {
234
- if (contains (p -> one , needle , len , regexp , kws ))
235
- has_changes ++ ;
236
- }
237
- else if (!diff_unmodified_pair (p ) &&
238
- contains (p -> one , needle , len , regexp , kws ) !=
239
- contains (p -> two , needle , len , regexp , kws ))
240
- has_changes ++ ;
241
- if (has_changes )
244
+ if (has_changes (p , needle , len , regexp , kws ))
242
245
goto out ; /* do not munge the queue */
243
246
}
244
247
@@ -254,25 +257,7 @@ static void diffcore_pickaxe_count(struct diff_options *o)
254
257
/* Showing only the filepairs that has the needle */
255
258
for (i = 0 ; i < q -> nr ; i ++ ) {
256
259
struct diff_filepair * p = q -> queue [i ];
257
- has_changes = 0 ;
258
- if (!DIFF_FILE_VALID (p -> one )) {
259
- if (!DIFF_FILE_VALID (p -> two ))
260
- ; /* ignore unmerged */
261
- /* created */
262
- else if (contains (p -> two , needle , len , regexp ,
263
- kws ))
264
- has_changes = 1 ;
265
- }
266
- else if (!DIFF_FILE_VALID (p -> two )) {
267
- if (contains (p -> one , needle , len , regexp , kws ))
268
- has_changes = 1 ;
269
- }
270
- else if (!diff_unmodified_pair (p ) &&
271
- contains (p -> one , needle , len , regexp , kws ) !=
272
- contains (p -> two , needle , len , regexp , kws ))
273
- has_changes = 1 ;
274
-
275
- if (has_changes )
260
+ if (has_changes (p , needle , len , regexp , kws ))
276
261
diff_q (& outq , p );
277
262
else
278
263
diff_free_filepair (p );
0 commit comments