diff: factor out match_filter()

diffcore_apply_filter() checks if a filepair matches the filter given with the "--diff-filter" option for each input filepairs with a fairly complex expression in two places. Create a helper function and call it. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jul 17, 2013 at 15:09 UTC 08578fa13eeec7079101f7ac52208aec83d54c62
1 file changed +13 -16
diff.c
+13 -16
@@ -4509,6 +4509,17 @@ free_queue:
4509 }
4510 }
4511
4512 +static int match_filter(const struct diff_options *options, const struct diff_filepair *p)
4513 +{
4514 + return (((p->status == DIFF_STATUS_MODIFIED) &&
4515 + ((p->score &&
4516 + strchr(options->filter, DIFF_STATUS_FILTER_BROKEN)) ||
4517 + (!p->score &&
4518 + strchr(options->filter, DIFF_STATUS_MODIFIED)))) ||
4519 + ((p->status != DIFF_STATUS_MODIFIED) &&
4520 + strchr(options->filter, p->status)));
4521 +}
4522 +
4523 static void diffcore_apply_filter(struct diff_options *options)
4524 {
4525 int i;
@@ -4524,14 +4535,7 @@ static void diffcore_apply_filter(struct diff_options *options)
4535 if (strchr(filter, DIFF_STATUS_FILTER_AON)) {
4536 int found;
4537 for (i = found = 0; !found && i < q->nr; i++) {
4527 - struct diff_filepair *p = q->queue[i];
4528 - if (((p->status == DIFF_STATUS_MODIFIED) &&
4529 - ((p->score &&
4530 - strchr(filter, DIFF_STATUS_FILTER_BROKEN)) ||
4531 - (!p->score &&
4532 - strchr(filter, DIFF_STATUS_MODIFIED)))) ||
4533 - ((p->status != DIFF_STATUS_MODIFIED) &&
4534 - strchr(filter, p->status)))
4538 + if (match_filter(options, q->queue[i]))
4539 found++;
4540 }
4541 if (found)
@@ -4549,14 +4553,7 @@ static void diffcore_apply_filter(struct diff_options *options)
4553 /* Only the matching ones */
4554 for (i = 0; i < q->nr; i++) {
4555 struct diff_filepair *p = q->queue[i];
4552 -
4553 - if (((p->status == DIFF_STATUS_MODIFIED) &&
4554 - ((p->score &&
4555 - strchr(filter, DIFF_STATUS_FILTER_BROKEN)) ||
4556 - (!p->score &&
4557 - strchr(filter, DIFF_STATUS_MODIFIED)))) ||
4558 - ((p->status != DIFF_STATUS_MODIFIED) &&
4559 - strchr(filter, p->status)))
4556 + if (match_filter(options, p))
4557 diff_q(&outq, p);
4558 else
4559 diff_free_filepair(p);