git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] diff-filter: be more careful when looking for negative bits

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Jan 26, 2022, 17:57 UTC
Message-ID
<220126.868rv2e5ts.gmgdl@evledraar.gmail.com>
In-Reply-To
<e8006493a9ed4da9b9125865e004ba7ace20e7a4.1643149759.git.gitgitgadget@gmail.com>
On Tue, Jan 25 2022, Johannes Schindelin via GitGitGadget wrote:
Show 37 quoted lines
> From: Johannes Schindelin <johannes.schindelin@gmx.de>
>
> The `--diff-filter=<bits>` 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.
>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
>  diff.c         | 8 +++-----
>  t/t4202-log.sh | 8 ++++++++
>  2 files changed, 11 insertions(+), 5 deletions(-)
>
> diff --git a/diff.c b/diff.c
> index c862771a589..fc1151b9c73 100644
> --- a/diff.c
> +++ b/diff.c
> @@ -4821,17 +4821,15 @@ static int diff_opt_diff_filter(const struct option *option,
>  	prepare_filter_bits();
>  
>  	/*
> -	 * If there is a negation e.g. 'd' in the input, and we haven't
> +	 * If the input starts with a negation e.g. 'd', 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;
> +		optch = optarg[0];
> +		if (optch >= 'a' && 'z' >= optch) {

We'll probably never have to deal with non-ASCII, so maybe this is being overzelous, but perhaps changing this to islower(optch) is worth it?

This relies on non-standard C both in the pre- and post-image, but in reality it works everywhere, until someone attempts to port git to an EBCDIC system...

Show 16 quoted lines
>  			opt->filter = (1 << (ARRAY_SIZE(diff_status_letters) - 1)) - 1;
>  			opt->filter &= ~filter_bit[DIFF_STATUS_FILTER_AON];
> -			break;
>  		}
>  	}
>  
> diff --git a/t/t4202-log.sh b/t/t4202-log.sh
> index 50495598619..28f727937dd 100755
> --- a/t/t4202-log.sh
> +++ b/t/t4202-log.sh
> @@ -142,6 +142,14 @@ test_expect_success 'diff-filter=R' '
>  
>  '
>  
> +test_expect_success 'diff-filter=Ra' '
> +
nit: extra \n
Show 9 quoted lines
> +	git log -M --pretty="format:%s" --diff-filter=R HEAD >expect &&
> +	git log -M --pretty="format:%s" --diff-filter=Ra HEAD >actual &&
> +	test_cmp expect actual
> +
> +'
> +
>  test_expect_success 'diff-filter=C' '
>  
>  	git log -C -C --pretty="format:%s" --diff-filter=C HEAD >actual &&
Previous: Johannes SchindelinNext: Johannes Schindelin via GitGitGadget
Message 11 of 21 in “Fix two --diff-filter bugs”
  1. 0/2 Fix two --diff-filter bugsJohannes Schindelin via GitGitGadget, Jan 25, 2022
  2. 1/2 docs(diff): lose incorrect claim about `diff-files --diff-filter=A`Johannes Schindelin via GitGitGadget, Jan 25, 2022
  3. Junio C HamanoJan 26, 2022
  4. 2/2 diff-filter: be more careful when looking for negative bitsJohannes Schindelin via GitGitGadget, Jan 25, 2022
  5. Taylor BlauJan 25, 2022
  6. Johannes SchindelinJan 28, 2022
  7. Junio C HamanoJan 26, 2022
  8. Taylor BlauJan 26, 2022
  9. Junio C HamanoJan 26, 2022
  10. Johannes SchindelinJan 28, 2022
  11. Ævar Arnfjörð BjarmasonJan 26, 2022
  12. 0/3 Fix two --diff-filter bugsJohannes Schindelin via GitGitGadget, Jan 27, 2022
  13. 1/3 docs(diff): lose incorrect claim about `diff-files --diff-filter=A`Johannes Schindelin via GitGitGadget, Jan 27, 2022
  14. 2/3 diff.c: move the diff filter bits definitions up a bitJohannes Schindelin via GitGitGadget, Jan 27, 2022
  15. 3/3 diff-filter: be more careful when looking for negative bitsJohannes Schindelin via GitGitGadget, Jan 27, 2022
  16. Junio C HamanoJan 28, 2022
  17. Johannes SchindelinJan 28, 2022
  18. 0/3 Fix two --diff-filter bugsJohannes Schindelin via GitGitGadget, Jan 28, 2022
  19. 1/3 docs(diff): lose incorrect claim about `diff-files --diff-filter=A`Johannes Schindelin via GitGitGadget, Jan 28, 2022
  20. 2/3 diff.c: move the diff filter bits definitions up a bitJohannes Schindelin via GitGitGadget, Jan 28, 2022
  21. 3/3 diff-filter: be more careful when looking for negative bitsJohannes Schindelin via GitGitGadget, Jan 28, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.