diff options
author | Junio C Hamano <gitster@pobox.com> | 2013-07-17 16:19:19 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2013-07-17 17:17:39 -0700 |
commit | 7f2ea5f0f2fb056314092cce23202096ca70f076 (patch) | |
tree | 32f7649879ec3012f3f92d659fee945b9aed265b /diff.c | |
parent | bf142ec4346385553918bc53f203b205091aa362 (diff) | |
download | git-7f2ea5f0f2fb056314092cce23202096ca70f076.tar.gz |
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>
Diffstat (limited to 'diff.c')
-rw-r--r-- | diff.c | 29 |
1 files changed, 28 insertions, 1 deletions
@@ -3532,13 +3532,40 @@ static int parse_diff_filter_opt(const char *optarg, struct diff_options *opt) int i, optch; prepare_filter_bits(); + + /* + * If there is a negation e.g. 'd' in the input, and we haven't + * initialized the filter field with another --diff-filter, start + * from full set of bits, except for AON. + */ + if (!opt->filter) { + for (i = 0; (optch = optarg[i]) != '\0'; i++) { + if (optch < 'a' || 'z' < optch) + continue; + opt->filter = (1 << (ARRAY_SIZE(diff_status_letters) - 1)) - 1; + opt->filter &= ~filter_bit[DIFF_STATUS_FILTER_AON]; + break; + } + } + for (i = 0; (optch = optarg[i]) != '\0'; i++) { unsigned int bit; + int negate; + + if ('a' <= optch && optch <= 'z') { + negate = 1; + optch = toupper(optch); + } else { + negate = 0; + } bit = (0 <= optch && optch <= 'Z') ? filter_bit[optch] : 0; if (!bit) return optarg[i]; - opt->filter |= bit; + if (negate) + opt->filter &= ~bit; + else + opt->filter |= bit; } return 0; } |