Skip to content

Commit

Permalink
diff: factor out match_filter()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Jul 17, 2013
1 parent 949226f commit 08578fa
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -4509,6 +4509,17 @@ void diff_flush(struct diff_options *options)
}
}

static int match_filter(const struct diff_options *options, const struct diff_filepair *p)
{
return (((p->status == DIFF_STATUS_MODIFIED) &&
((p->score &&
strchr(options->filter, DIFF_STATUS_FILTER_BROKEN)) ||
(!p->score &&
strchr(options->filter, DIFF_STATUS_MODIFIED)))) ||
((p->status != DIFF_STATUS_MODIFIED) &&
strchr(options->filter, p->status)));
}

static void diffcore_apply_filter(struct diff_options *options)
{
int i;
Expand All @@ -4524,14 +4535,7 @@ static void diffcore_apply_filter(struct diff_options *options)
if (strchr(filter, DIFF_STATUS_FILTER_AON)) {
int found;
for (i = found = 0; !found && i < q->nr; i++) {
struct diff_filepair *p = q->queue[i];
if (((p->status == DIFF_STATUS_MODIFIED) &&
((p->score &&
strchr(filter, DIFF_STATUS_FILTER_BROKEN)) ||
(!p->score &&
strchr(filter, DIFF_STATUS_MODIFIED)))) ||
((p->status != DIFF_STATUS_MODIFIED) &&
strchr(filter, p->status)))
if (match_filter(options, q->queue[i]))
found++;
}
if (found)
Expand All @@ -4549,14 +4553,7 @@ static void diffcore_apply_filter(struct diff_options *options)
/* Only the matching ones */
for (i = 0; i < q->nr; i++) {
struct diff_filepair *p = q->queue[i];

if (((p->status == DIFF_STATUS_MODIFIED) &&
((p->score &&
strchr(filter, DIFF_STATUS_FILTER_BROKEN)) ||
(!p->score &&
strchr(filter, DIFF_STATUS_MODIFIED)))) ||
((p->status != DIFF_STATUS_MODIFIED) &&
strchr(filter, p->status)))
if (match_filter(options, p))
diff_q(&outq, p);
else
diff_free_filepair(p);
Expand Down

0 comments on commit 08578fa

Please sign in to comment.