Skip to content

Commit 7f2ea5f

Browse files
committed
diff: allow lowercase letter to specify what change class to exclude
In order to express "we do not care about deletions", we had to say "--diff-filter=ACMRTXUB", giving all the possible change class except for the one we do not want, "D". This is cumbersome. As all the change classes are in uppercase, allow their lowercase counterpart to selectively exclude the class from the output. When such a negated change class is in the input, start the filter option with the full bits set. This would allow us to express the old "show-diff -q" with "git diff-files --diff-filter=d". Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent bf142ec commit 7f2ea5f

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

diff.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3532,13 +3532,40 @@ static int parse_diff_filter_opt(const char *optarg, struct diff_options *opt)
35323532
int i, optch;
35333533

35343534
prepare_filter_bits();
3535+
3536+
/*
3537+
* If there is a negation e.g. 'd' in the input, and we haven't
3538+
* initialized the filter field with another --diff-filter, start
3539+
* from full set of bits, except for AON.
3540+
*/
3541+
if (!opt->filter) {
3542+
for (i = 0; (optch = optarg[i]) != '\0'; i++) {
3543+
if (optch < 'a' || 'z' < optch)
3544+
continue;
3545+
opt->filter = (1 << (ARRAY_SIZE(diff_status_letters) - 1)) - 1;
3546+
opt->filter &= ~filter_bit[DIFF_STATUS_FILTER_AON];
3547+
break;
3548+
}
3549+
}
3550+
35353551
for (i = 0; (optch = optarg[i]) != '\0'; i++) {
35363552
unsigned int bit;
3553+
int negate;
3554+
3555+
if ('a' <= optch && optch <= 'z') {
3556+
negate = 1;
3557+
optch = toupper(optch);
3558+
} else {
3559+
negate = 0;
3560+
}
35373561

35383562
bit = (0 <= optch && optch <= 'Z') ? filter_bit[optch] : 0;
35393563
if (!bit)
35403564
return optarg[i];
3541-
opt->filter |= bit;
3565+
if (negate)
3566+
opt->filter &= ~bit;
3567+
else
3568+
opt->filter |= bit;
35423569
}
35433570
return 0;
35443571
}

0 commit comments

Comments
 (0)