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

Re: [PATCH] check-ignore: --non-matching without --verbose

From
Derrick Stolee <derrickstolee@github.com>
Date
May 23, 2022, 20:44 UTC
Message-ID
<362128ff-690d-8dc1-88fd-620f52b14d54@github.com>
In-Reply-To
<pull.1236.git.1653310466062.gitgitgadget@gmail.com>
On 5/23/2022 8:54 AM, Carl Smedstad via GitGitGadget wrote:
> From: Carl Smedstad <carl.smedstad@protonmail.com>
Show 7 quoted lines
>  -n, --non-matching::
> -	Show given paths which don't match any pattern.	 This only
> -	makes sense when `--verbose` is enabled, otherwise it would
> -	not be possible to distinguish between paths which match a
> -	pattern and those which don't.
> +	Only show given paths which don't match any pattern. If `--verbose` is
> +	enabled, show both paths that match a pattern and those which don't.

This may be better to indicate the behavior as predicated on the existence of --verbose:

	If `--verbose` is enabled, then all paths are listed along
	with an indicator (`::`) that no matching pattern was found.
	Without `--verbose`, list only the paths that do not match
	any pattern.
Show 11 quoted lines
> -		if (!quiet && (pattern || show_non_matching))
> -			output_pattern(pathspec.items[i].original, pattern);
> +		if (!quiet) {
> +			if (verbose) {
> +				if (show_non_matching || pattern)
> +					output_pattern(pathspec.items[i].original, pattern);
> +			} else {
> +				if (show_non_matching && !pattern)
> +					output_pattern(pathspec.items[i].original, pattern);
> +				if (!show_non_matching && pattern)
> +					output_pattern(pathspec.items[i].original, pattern);

These three blocks all call the same code line. So really you want to avoid a single case:

	if (!quiet &&
	    ((verbose && (show_non_matching || pattern)) ||
	     (!verbose && !!show_non_matching != !!pattern)))

This is the most direct way to write what you had above. However, we could do this more simply:

	/* If --non-matching, then show if verbose or the pattern is missing. */
	if (!quiet && show_non_matching && (verbose || !pattern))
		output_pattern(...);
	/* If not --non-matching, then show if the pattern exists. */
	if (!quiet && !show_non_matching && pattern)
		output_pattern(...);

Hopefully that's a bit easier to parse. I believe it is equivalent.

Thanks, -Stolee

Previous: Ævar Arnfjörð BjarmasonNext: Carl Smedstad
Message 6 of 9 in “check-ignore: --non-matching without --verbose”
  1. check-ignore: --non-matching without --verboseCarl Smedstad via GitGitGadget, May 23, 2022
  2. Junio C HamanoMay 23, 2022
  3. Carl SmedstadMay 24, 2022
  4. Junio C HamanoMay 24, 2022
  5. Ævar Arnfjörð BjarmasonMay 24, 2022
  6. Derrick StoleeMay 23, 2022
  7. Carl SmedstadMay 24, 2022
  8. check-ignore: --non-matching without --verboseCarl Smedstad via GitGitGadget, May 24, 2022
  9. Junio C HamanoMay 24, 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.