All of lore.kernel.org
 help / color / mirror / Atom feed
From: Derrick Stolee <derrickstolee@github.com>
To: Carl Smedstad via GitGitGadget <gitgitgadget@gmail.com>,
	git@vger.kernel.org
Cc: Carl Smedstad <carl.smedstad@protonmail.com>
Subject: Re: [PATCH] check-ignore: --non-matching without --verbose
Date: Mon, 23 May 2022 16:44:55 -0400	[thread overview]
Message-ID: <362128ff-690d-8dc1-88fd-620f52b14d54@github.com> (raw)
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>

>  -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.

> -		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

  parent reply	other threads:[~2022-05-23 20:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-23 12:54 [PATCH] check-ignore: --non-matching without --verbose Carl Smedstad via GitGitGadget
2022-05-23 18:14 ` Junio C Hamano
2022-05-24 13:03   ` Carl Smedstad
2022-05-24 19:18     ` Junio C Hamano
2022-05-24 19:26       ` Ævar Arnfjörð Bjarmason
2022-05-23 20:44 ` Derrick Stolee [this message]
2022-05-24 13:06   ` Carl Smedstad
2022-05-24 13:01 ` [PATCH v2] " Carl Smedstad via GitGitGadget
2022-05-24 17:45 ` [PATCH] " Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=362128ff-690d-8dc1-88fd-620f52b14d54@github.com \
    --to=derrickstolee@github.com \
    --cc=carl.smedstad@protonmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.