Skip to content

Commit 08578fa

Browse files
committed
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>
1 parent 949226f commit 08578fa

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

diff.c

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4509,6 +4509,17 @@ void diff_flush(struct diff_options *options)
45094509
}
45104510
}
45114511

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+
45124523
static void diffcore_apply_filter(struct diff_options *options)
45134524
{
45144525
int i;
@@ -4524,14 +4535,7 @@ static void diffcore_apply_filter(struct diff_options *options)
45244535
if (strchr(filter, DIFF_STATUS_FILTER_AON)) {
45254536
int found;
45264537
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]))
45354539
found++;
45364540
}
45374541
if (found)
@@ -4549,14 +4553,7 @@ static void diffcore_apply_filter(struct diff_options *options)
45494553
/* Only the matching ones */
45504554
for (i = 0; i < q->nr; i++) {
45514555
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))
45604557
diff_q(&outq, p);
45614558
else
45624559
diff_free_filepair(p);

0 commit comments

Comments
 (0)