From 75408ca94980c125b3a800003c3e6b7cdcb27d44 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 28 Jan 2022 12:02:50 +0000 Subject: diff-filter: be more careful when looking for negative bits The `--diff-filter=` option allows to filter the diff by certain criteria, for example `R` to only show renamed files. It also supports negating a filter via a down-cased letter, i.e. `r` to show _everything but_ renamed files. However, the code is a bit overzealous when trying to figure out whether `git diff` should start with all diff-filters turned on because the user provided a lower-case letter: if the `--diff-filter` argument starts with an upper-case letter, we must not start with all bits turned on. Even worse, it is possible to specify the diff filters in multiple, separate options, e.g. `--diff-filter=AM [...] --diff-filter=m`. Let's accumulate the include/exclude filters independently, and only special-case the "only exclude filters were specified" case after parsing the options altogether. Note: The code replaced by this commit took pains to avoid setting any unused bits of `options->filter`. That was unnecessary, though, as all accesses happen via the `filter_bit_tst()` function using specific bits, and setting the unused bits has no effect. Therefore, we can simplify the code by using `~0` (or in this instance, `~`). Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- diff.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'diff.h') diff --git a/diff.h b/diff.h index 8ba85c5e60..a70e7c478c 100644 --- a/diff.h +++ b/diff.h @@ -283,7 +283,7 @@ struct diff_options { struct diff_flags flags; /* diff-filter bits */ - unsigned int filter; + unsigned int filter, filter_not; int use_color; -- cgit v1.2.3