{"thread":{"id":"57912","subject":"[PATCH] check-ignore: --non-matching without --verbose","startedAt":"2022-05-23T12:54:47Z","lastAt":"2022-05-24T19:27:49Z","messageCount":9,"participants":["Carl Smedstad via GitGitGadget","Junio C Hamano","Derrick Stolee","Carl Smedstad","Ævar Arnfjörð Bjarmason"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"455764","messageId":"pull.1236.git.1653310466062.gitgitgadget@gmail.com","threadId":"57912","inReplyTo":null,"subject":"[PATCH] check-ignore: --non-matching without --verbose","fromName":"Carl Smedstad via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-05-23T12:54:25Z","receivedAt":"2022-05-23T12:54:47Z","isPatch":true,"sender":{"key":"carl.smedstad@protonmail.com","avatar":null},"body":"From: Carl Smedstad <carl.smedstad@protonmail.com>\n\nAllow --non-matching to be specified without the --verbose flag to make\ngit only list files that are not matching any pattern. The behaviour\nwhen specifying both --non-matching and --verbose is unchanged.\n\nThe motivation for this is to use the underutilized invocation of\n--non-matching without --verbose to create a shorthand for what could be\nachieved by:\n\n    find . |\n      git check-ignore --verbose --non-matching |\n      grep $'^::\\t' |\n      sed -e 's/.*\\t//'\n\nSigned-off-by: Carl Smedstad <carl.smedstad@protonmail.com>\n---\n    check-ignore: --non-matching without --verbose\n    \n    Allow --non-matching to be specified without the --verbose flag to make\n    git only list files that are not matching any pattern. The behaviour\n    when specifying both --non-matching and --verbose is unchanged.\n    \n    The motivation for this is to use the underutilized invocation of\n    --non-matching without --verbose to create a shorthand for what could be\n    achieved by:\n    \n    find . |\n      git check-ignore --verbose --non-matching |\n      grep $'^::\\t' |\n      sed -e 's/.*\\t//'\n    \n    \n    Signed-off-by: Carl Smedstad carl.smedstad@protonmail.com\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-1236%2Fcarlsmedstad%2Fcheck-ignore-non-matching-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1236/carlsmedstad/check-ignore-non-matching-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/1236\n\n Documentation/git-check-ignore.txt |  6 ++----\n builtin/check-ignore.c             | 15 +++++++++++----\n t/t0008-ignores.sh                 | 17 +++++++++++++++--\n 3 files changed, 28 insertions(+), 10 deletions(-)\n\ndiff --git a/Documentation/git-check-ignore.txt b/Documentation/git-check-ignore.txt\nindex 2892799e32f..69d12fd22e1 100644\n--- a/Documentation/git-check-ignore.txt\n+++ b/Documentation/git-check-ignore.txt\n@@ -50,10 +50,8 @@ linkgit:gitignore[5].\n \twith a NUL character instead of a linefeed character.\n \n -n, --non-matching::\n-\tShow given paths which don't match any pattern.\t This only\n-\tmakes sense when `--verbose` is enabled, otherwise it would\n-\tnot be possible to distinguish between paths which match a\n-\tpattern and those which don't.\n+\tOnly show given paths which don't match any pattern. If `--verbose` is\n+\tenabled, show both paths that match a pattern and those which don't.\n \n --no-index::\n \tDon't look in the index when undertaking the checks. This can\ndiff --git a/builtin/check-ignore.c b/builtin/check-ignore.c\nindex 21912569650..10e8bba1057 100644\n--- a/builtin/check-ignore.c\n+++ b/builtin/check-ignore.c\n@@ -113,8 +113,17 @@ static int check_ignore(struct dir_struct *dir,\n \t\t\t    pattern->flags & PATTERN_FLAG_NEGATIVE)\n \t\t\t\tpattern = NULL;\n \t\t}\n-\t\tif (!quiet && (pattern || show_non_matching))\n-\t\t\toutput_pattern(pathspec.items[i].original, pattern);\n+\t\tif (!quiet) {\n+\t\t\tif (verbose) {\n+\t\t\t\tif (show_non_matching || pattern)\n+\t\t\t\t\toutput_pattern(pathspec.items[i].original, pattern);\n+\t\t\t} else {\n+\t\t\t\tif (show_non_matching && !pattern)\n+\t\t\t\t\toutput_pattern(pathspec.items[i].original, pattern);\n+\t\t\t\tif (!show_non_matching && pattern)\n+\t\t\t\t\toutput_pattern(pathspec.items[i].original, pattern);\n+\t\t\t}\n+\t\t}\n \t\tif (pattern)\n \t\t\tnum_ignored++;\n \t}\n@@ -175,8 +184,6 @@ int cmd_check_ignore(int argc, const char **argv, const char *prefix)\n \t\tif (verbose)\n \t\t\tdie(_(\"cannot have both --quiet and --verbose\"));\n \t}\n-\tif (show_non_matching && !verbose)\n-\t\tdie(_(\"--non-matching is only valid with --verbose\"));\n \n \t/* read_cache() is only necessary so we can watch out for submodules. */\n \tif (!no_index && read_cache() < 0)\ndiff --git a/t/t0008-ignores.sh b/t/t0008-ignores.sh\nindex 5575dade8ee..2ea178797bc 100755\n--- a/t/t0008-ignores.sh\n+++ b/t/t0008-ignores.sh\n@@ -90,7 +90,8 @@ test_check_ignore () {\n #   1. with -q / --quiet\n #   2. with default verbosity\n #   3. with -v / --verbose\n-#   4. with -v / --verbose, *and* -n / --non-matching\n+#   4. with -n / --non-matching\n+#   5. with -v / --verbose, *and* -n / --non-matching\n #\n # expecting success each time.  Takes advantage of the fact that\n # check-ignore --verbose output is the same as normal output except\n@@ -102,7 +103,7 @@ test_check_ignore () {\n # Arguments:\n #   - (optional) prereqs for this test, e.g. 'SYMLINKS'\n #   - test name\n-#   - output to expect from the fourth verbosity mode (the output\n+#   - output to expect from the fifth verbosity mode (the output\n #     from the other verbosity modes is automatically inferred\n #     from this value)\n #   - code to run (should invoke test_check_ignore)\n@@ -124,6 +125,7 @@ test_expect_success_multiple () {\n \n \texpect_verbose=$( echo \"$expect_all\" | grep -v '^::\t' )\n \texpect=$( echo \"$expect_verbose\" | sed -e 's/.*\t//' )\n+\texpect_non_matching=$( echo \"$expect_all\" | grep '^::\t' | sed -e 's/.*\t//')\n \n \ttest_expect_success $prereq \"$testname${no_index_opt:+ with $no_index_opt}\" '\n \t\texpect \"$expect\" &&\n@@ -144,6 +146,17 @@ test_expect_success_multiple () {\n \t\tquiet_opt=\n \tfi\n \n+\tfor non_matching_opt in '-n' '--non-matching'\n+\tdo\n+\t\ttest_code=\"\n+\t\t\texpect '$expect_non_matching' &&\n+\t\t\t$code\n+\t\t\"\n+\t\topts=\"${no_index_opt:+$no_index_opt }$non_matching_opt\"\n+\t\ttest_expect_success $prereq \"$testname${opts:+ with $opts}\" \"$test_code\"\n+\tdone\n+\tnon_matching_opt=\n+\n \tfor verbose_opt in '-v' '--verbose'\n \tdo\n \t\tfor non_matching_opt in '' '-n' '--non-matching'\n\nbase-commit: f9b95943b68b6b8ca5a6072f50a08411c6449b55\n-- \ngitgitgadget\n"},{"id":"455802","messageId":"xmqqilpwru9z.fsf@gitster.g","threadId":"57912","inReplyTo":"pull.1236.git.1653310466062.gitgitgadget@gmail.com","subject":"Re: [PATCH] check-ignore: --non-matching without --verbose","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-05-23T18:14:16Z","receivedAt":"2022-05-23T18:48:49Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Carl Smedstad via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> The motivation for this is to use the underutilized invocation of\n> --non-matching without --verbose to create a shorthand for what could be\n> achieved by:\n\nNot commenting on the patch itself, but ...\n\n>\n>     find . |\n>       git check-ignore --verbose --non-matching |\n>       grep $'^::\\t' |\n>       sed -e 's/.*\\t//'\n\n... feeding grep output to sed caught my eyes.  Isn't that equivalent to\n\n\tgit ... |\n\tsed -n '/^::\\t/s/.*\\t//p'\n\n?\n"},{"id":"455851","messageId":"362128ff-690d-8dc1-88fd-620f52b14d54@github.com","threadId":"57912","inReplyTo":"pull.1236.git.1653310466062.gitgitgadget@gmail.com","subject":"Re: [PATCH] check-ignore: --non-matching without --verbose","fromName":"Derrick Stolee","fromEmail":"derrickstolee@github.com","sentAt":"2022-05-23T20:44:55Z","receivedAt":"2022-05-23T20:45:06Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 5/23/2022 8:54 AM, Carl Smedstad via GitGitGadget wrote:\n> From: Carl Smedstad <carl.smedstad@protonmail.com>\n\n>  -n, --non-matching::\n> -\tShow given paths which don't match any pattern.\t This only\n> -\tmakes sense when `--verbose` is enabled, otherwise it would\n> -\tnot be possible to distinguish between paths which match a\n> -\tpattern and those which don't.\n> +\tOnly show given paths which don't match any pattern. If `--verbose` is\n> +\tenabled, show both paths that match a pattern and those which don't.\n\nThis may be better to indicate the behavior as predicated on the\nexistence of --verbose:\n\n\tIf `--verbose` is enabled, then all paths are listed along\n\twith an indicator (`::`) that no matching pattern was found.\n\tWithout `--verbose`, list only the paths that do not match\n\tany pattern.\n\n> -\t\tif (!quiet && (pattern || show_non_matching))\n> -\t\t\toutput_pattern(pathspec.items[i].original, pattern);\n> +\t\tif (!quiet) {\n> +\t\t\tif (verbose) {\n> +\t\t\t\tif (show_non_matching || pattern)\n> +\t\t\t\t\toutput_pattern(pathspec.items[i].original, pattern);\n> +\t\t\t} else {\n> +\t\t\t\tif (show_non_matching && !pattern)\n> +\t\t\t\t\toutput_pattern(pathspec.items[i].original, pattern);\n> +\t\t\t\tif (!show_non_matching && pattern)\n> +\t\t\t\t\toutput_pattern(pathspec.items[i].original, pattern);\n\nThese three blocks all call the same code line. So really you want\nto avoid a single case:\n\n\tif (!quiet &&\n\t    ((verbose && (show_non_matching || pattern)) ||\n\t     (!verbose && !!show_non_matching != !!pattern)))\n\nThis is the most direct way to write what you had above. However,\nwe could do this more simply:\n\n\t/* If --non-matching, then show if verbose or the pattern is missing. */\n\tif (!quiet && show_non_matching && (verbose || !pattern))\n\t\toutput_pattern(...);\n\n\t/* If not --non-matching, then show if the pattern exists. */\n\tif (!quiet && !show_non_matching && pattern)\n\t\toutput_pattern(...);\n\nHopefully that's a bit easier to parse. I believe it is\nequivalent.\n\nThanks,\n-Stolee\n"},{"id":"455898","messageId":"pull.1236.v2.git.1653397315122.gitgitgadget@gmail.com","threadId":"57912","inReplyTo":"pull.1236.git.1653310466062.gitgitgadget@gmail.com","subject":"[PATCH v2] check-ignore: --non-matching without --verbose","fromName":"Carl Smedstad via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-05-24T13:01:54Z","receivedAt":"2022-05-24T13:02:03Z","isPatch":true,"sender":{"key":"carl.smedstad@protonmail.com","avatar":null},"body":"From: Carl Smedstad <carl.smedstad@protonmail.com>\n\nAllow --non-matching to be specified without the --verbose flag to make\ngit only list files that are not matching any pattern. The behaviour\nwhen specifying both --non-matching and --verbose is unchanged.\n\nThe motivation for this is to use the underutilized invocation of\n--non-matching without --verbose to create a shorthand for what could be\nachieved by:\n\n    find . |\n      git check-ignore --verbose --non-matching --stdin |\n      grep $'^::\\t' |\n      sed -e 's/.*\\t//'\n\nSigned-off-by: Carl Smedstad <carl.smedstad@protonmail.com>\n---\n    check-ignore: --non-matching without --verbose\n    \n    Changes since v1:\n    \n     * Rewrote description for --non-matching.\n     * Simplified the logic.\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-1236%2Fcarlsmedstad%2Fcheck-ignore-non-matching-v2\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1236/carlsmedstad/check-ignore-non-matching-v2\nPull-Request: https://github.com/gitgitgadget/git/pull/1236\n\nRange-diff vs v1:\n\n 1:  de794d0af18 ! 1:  350a3cfea1b check-ignore: --non-matching without --verbose\n     @@ Commit message\n          achieved by:\n      \n              find . |\n     -          git check-ignore --verbose --non-matching |\n     +          git check-ignore --verbose --non-matching --stdin |\n                grep $'^::\\t' |\n                sed -e 's/.*\\t//'\n      \n     @@ Documentation/git-check-ignore.txt: linkgit:gitignore[5].\n      -\tmakes sense when `--verbose` is enabled, otherwise it would\n      -\tnot be possible to distinguish between paths which match a\n      -\tpattern and those which don't.\n     -+\tOnly show given paths which don't match any pattern. If `--verbose` is\n     -+\tenabled, show both paths that match a pattern and those which don't.\n     ++\tIf `--verbose` is enabled, list both matching and non-matching\n     ++\tpaths (non-matching paths along with the indicator `::`). Without\n     ++\t`--verbose`, list only the paths that do not match any pattern.\n       \n       --no-index::\n       \tDon't look in the index when undertaking the checks. This can\n     @@ builtin/check-ignore.c: static int check_ignore(struct dir_struct *dir,\n       \t\t\t\tpattern = NULL;\n       \t\t}\n      -\t\tif (!quiet && (pattern || show_non_matching))\n     --\t\t\toutput_pattern(pathspec.items[i].original, pattern);\n     -+\t\tif (!quiet) {\n     -+\t\t\tif (verbose) {\n     -+\t\t\t\tif (show_non_matching || pattern)\n     -+\t\t\t\t\toutput_pattern(pathspec.items[i].original, pattern);\n     -+\t\t\t} else {\n     -+\t\t\t\tif (show_non_matching && !pattern)\n     -+\t\t\t\t\toutput_pattern(pathspec.items[i].original, pattern);\n     -+\t\t\t\tif (!show_non_matching && pattern)\n     -+\t\t\t\t\toutput_pattern(pathspec.items[i].original, pattern);\n     -+\t\t\t}\n     -+\t\t}\n     ++\n     ++\t\t/* If --non-matching, then show if verbose or the pattern is missing. */\n     ++\t\tif (!quiet && show_non_matching && (verbose || !pattern))\n     ++\t\t\toutput_pattern(pathspec.items[i].original, pattern);\n     ++\n     ++\t\t/* If not --non-matching, then show if the pattern exists. */\n     ++\t\tif (!quiet && !show_non_matching && pattern)\n     + \t\t\toutput_pattern(pathspec.items[i].original, pattern);\n     ++\n       \t\tif (pattern)\n       \t\t\tnum_ignored++;\n       \t}\n\n\n Documentation/git-check-ignore.txt |  7 +++----\n builtin/check-ignore.c             | 11 ++++++++---\n t/t0008-ignores.sh                 | 17 +++++++++++++++--\n 3 files changed, 26 insertions(+), 9 deletions(-)\n\ndiff --git a/Documentation/git-check-ignore.txt b/Documentation/git-check-ignore.txt\nindex 2892799e32f..bb096875ca3 100644\n--- a/Documentation/git-check-ignore.txt\n+++ b/Documentation/git-check-ignore.txt\n@@ -50,10 +50,9 @@ linkgit:gitignore[5].\n \twith a NUL character instead of a linefeed character.\n \n -n, --non-matching::\n-\tShow given paths which don't match any pattern.\t This only\n-\tmakes sense when `--verbose` is enabled, otherwise it would\n-\tnot be possible to distinguish between paths which match a\n-\tpattern and those which don't.\n+\tIf `--verbose` is enabled, list both matching and non-matching\n+\tpaths (non-matching paths along with the indicator `::`). Without\n+\t`--verbose`, list only the paths that do not match any pattern.\n \n --no-index::\n \tDon't look in the index when undertaking the checks. This can\ndiff --git a/builtin/check-ignore.c b/builtin/check-ignore.c\nindex 21912569650..46108ac8593 100644\n--- a/builtin/check-ignore.c\n+++ b/builtin/check-ignore.c\n@@ -113,8 +113,15 @@ static int check_ignore(struct dir_struct *dir,\n \t\t\t    pattern->flags & PATTERN_FLAG_NEGATIVE)\n \t\t\t\tpattern = NULL;\n \t\t}\n-\t\tif (!quiet && (pattern || show_non_matching))\n+\n+\t\t/* If --non-matching, then show if verbose or the pattern is missing. */\n+\t\tif (!quiet && show_non_matching && (verbose || !pattern))\n+\t\t\toutput_pattern(pathspec.items[i].original, pattern);\n+\n+\t\t/* If not --non-matching, then show if the pattern exists. */\n+\t\tif (!quiet && !show_non_matching && pattern)\n \t\t\toutput_pattern(pathspec.items[i].original, pattern);\n+\n \t\tif (pattern)\n \t\t\tnum_ignored++;\n \t}\n@@ -175,8 +182,6 @@ int cmd_check_ignore(int argc, const char **argv, const char *prefix)\n \t\tif (verbose)\n \t\t\tdie(_(\"cannot have both --quiet and --verbose\"));\n \t}\n-\tif (show_non_matching && !verbose)\n-\t\tdie(_(\"--non-matching is only valid with --verbose\"));\n \n \t/* read_cache() is only necessary so we can watch out for submodules. */\n \tif (!no_index && read_cache() < 0)\ndiff --git a/t/t0008-ignores.sh b/t/t0008-ignores.sh\nindex 5575dade8ee..2ea178797bc 100755\n--- a/t/t0008-ignores.sh\n+++ b/t/t0008-ignores.sh\n@@ -90,7 +90,8 @@ test_check_ignore () {\n #   1. with -q / --quiet\n #   2. with default verbosity\n #   3. with -v / --verbose\n-#   4. with -v / --verbose, *and* -n / --non-matching\n+#   4. with -n / --non-matching\n+#   5. with -v / --verbose, *and* -n / --non-matching\n #\n # expecting success each time.  Takes advantage of the fact that\n # check-ignore --verbose output is the same as normal output except\n@@ -102,7 +103,7 @@ test_check_ignore () {\n # Arguments:\n #   - (optional) prereqs for this test, e.g. 'SYMLINKS'\n #   - test name\n-#   - output to expect from the fourth verbosity mode (the output\n+#   - output to expect from the fifth verbosity mode (the output\n #     from the other verbosity modes is automatically inferred\n #     from this value)\n #   - code to run (should invoke test_check_ignore)\n@@ -124,6 +125,7 @@ test_expect_success_multiple () {\n \n \texpect_verbose=$( echo \"$expect_all\" | grep -v '^::\t' )\n \texpect=$( echo \"$expect_verbose\" | sed -e 's/.*\t//' )\n+\texpect_non_matching=$( echo \"$expect_all\" | grep '^::\t' | sed -e 's/.*\t//')\n \n \ttest_expect_success $prereq \"$testname${no_index_opt:+ with $no_index_opt}\" '\n \t\texpect \"$expect\" &&\n@@ -144,6 +146,17 @@ test_expect_success_multiple () {\n \t\tquiet_opt=\n \tfi\n \n+\tfor non_matching_opt in '-n' '--non-matching'\n+\tdo\n+\t\ttest_code=\"\n+\t\t\texpect '$expect_non_matching' &&\n+\t\t\t$code\n+\t\t\"\n+\t\topts=\"${no_index_opt:+$no_index_opt }$non_matching_opt\"\n+\t\ttest_expect_success $prereq \"$testname${opts:+ with $opts}\" \"$test_code\"\n+\tdone\n+\tnon_matching_opt=\n+\n \tfor verbose_opt in '-v' '--verbose'\n \tdo\n \t\tfor non_matching_opt in '' '-n' '--non-matching'\n\nbase-commit: f9b95943b68b6b8ca5a6072f50a08411c6449b55\n-- \ngitgitgadget\n"},{"id":"455899","messageId":"hl3lllnkPVswb8IZoaMCS62N42epy97_8rLH8qrvSGCbKoovP5_qjtq4nrot5-h-q_7KOu-JpPX4nC0f74BXm6uWdtxosa6z5niHqAJKRUw=@protonmail.com","threadId":"57912","inReplyTo":"xmqqilpwru9z.fsf@gitster.g","subject":"Re: [PATCH] check-ignore: --non-matching without --verbose","fromName":"Carl Smedstad","fromEmail":"carl.smedstad@protonmail.com","sentAt":"2022-05-24T13:03:55Z","receivedAt":"2022-05-24T13:04:08Z","isPatch":true,"sender":{"key":"carl.smedstad@protonmail.com","avatar":null},"body":"> Not commenting on the patch itself, but ...\n>\n> > find . |\n> > git check-ignore --verbose --non-matching |\n> > grep $'^::\\t' |\n> > sed -e 's/.*\\t//'\n>\n> ... feeding grep output to sed caught my eyes. Isn't that equivalent to\n>\n> git ... |\n> sed -n '/^::\\t/s/.*\\t//p'\n\nThat is indeed equivalent. TIL about regular-expression addresses in\nsed, thanks!\n"},{"id":"455900","messageId":"qzzAQ1fG52vlhFocoEqahGa8X0FRYpdAzxAHP6NwLXvMFuu0eZQzoa2ew3b1I31puAx__Cr3I2EZObON40rN0UWKT_rSXY3F0tuPqmh2aNc=@protonmail.com","threadId":"57912","inReplyTo":"362128ff-690d-8dc1-88fd-620f52b14d54@github.com","subject":"Re: [PATCH] check-ignore: --non-matching without --verbose","fromName":"Carl Smedstad","fromEmail":"carl.smedstad@protonmail.com","sentAt":"2022-05-24T13:06:27Z","receivedAt":"2022-05-24T13:06:42Z","isPatch":true,"sender":{"key":"carl.smedstad@protonmail.com","avatar":null},"body":"> This may be better to indicate the behavior as predicated on the\n> existence of --verbose:\n>\n> \tIf `--verbose` is enabled, then all paths are listed along\n> \twith an indicator (`::`) that no matching pattern was found.\n> \tWithout `--verbose`, list only the paths that do not match\n> \tany pattern.\n\nGood point. I've adopted you changes but made some slight changes to the first\nline:\n\n\tIf `--verbose` is enabled, list both matching and non-matching\n\tpaths (non-matching paths along with the indicator `::`). Without\n\t`--verbose`, list only the paths that do not match any pattern.\n\n> These three blocks all call the same code line. So really you want\n> to avoid a single case:\n>\n> \tif (!quiet &&\n> \t    ((verbose && (show_non_matching || pattern)) ||\n> \t     (!verbose && !!show_non_matching != !!pattern)))\n>\n> This is the most direct way to write what you had above. However,\n> we could do this more simply:\n>\n> \t/* If --non-matching, then show if verbose or the pattern is missing. */\n> \tif (!quiet && show_non_matching && (verbose || !pattern))\n> \t\toutput_pattern(...);\n>\n> \t/* If not --non-matching, then show if the pattern exists. */\n> \tif (!quiet && !show_non_matching && pattern)\n> \t\toutput_pattern(...);\n>\n> Hopefully that's a bit easier to parse. I believe it is\n> equivalent.\n\nThat is indeed equivalent and a lot easier to read. Implemented the changes in\nfull. Thanks!\n"},{"id":"455918","messageId":"xmqqfskyj04e.fsf@gitster.g","threadId":"57912","inReplyTo":"pull.1236.git.1653310466062.gitgitgadget@gmail.com","subject":"Re: [PATCH] check-ignore: --non-matching without --verbose","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-05-24T17:45:05Z","receivedAt":"2022-05-24T17:45:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Carl Smedstad via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n>  -n, --non-matching::\n> -\tShow given paths which don't match any pattern.\t This only\n> -\tmakes sense when `--verbose` is enabled, otherwise it would\n> -\tnot be possible to distinguish between paths which match a\n> -\tpattern and those which don't.\n\nOK.  In the current code, verbose mode output can show both the\npattern that decided the fate for the path and the path itself, so\nwe can afford to include paths that match and that do not match.\nThere may not be any pattern that matched the path, or the last\npattern that matched the path was negative, or the last pattern that\nmatched was positive.  Users can tell them apart (the first two\ncases are the paths that do not match, the last case is the paths\nthat do match).  But non-verbose mode only show paths, so showing\nboth matched and non-matching paths to the output would not make\nsense.  But we document that it is a silly thing to ask, and\nexplicitly reject the combination of non-verbose option and\n--non-matching option.\n\nSo the option is misnamed; it is more like 'include-non-matching',\nnot 'non-matching-only'.\n\n> +\tOnly show given paths which don't match any pattern. If `--verbose` is\n> +\tenabled, show both paths that match a pattern and those which don't.\n\nBut this patch proposes the option to 'non-matching-only' only in\nnon-verbose mode.  Since \"check-ignore --non-matching <pathspec>\"\nwithout \"--verbose\" immediately errors out, making it do something\ndifferent does not have too much backward-compatibility worries.\n\nIt may be confusing to the users that the set of paths included in\nthe output, when the same \"-n\" option is given, were different\nbetween the non-verbose and the verbose mode.  That is one thing I\nfeel uncomfortable about this change.\n\nI wonder if we are better off to invent a new \"--non-matching-only\"\noption, have it support both the non-verbose and the verbose mode,\nand leave the current \"-n\" alone, with an option to perhaps giving\n\"--include-non-matching\" alias to the latter to clarify?\n\n> diff --git a/builtin/check-ignore.c b/builtin/check-ignore.c\n> index 21912569650..10e8bba1057 100644\n> --- a/builtin/check-ignore.c\n> +++ b/builtin/check-ignore.c\n> @@ -113,8 +113,17 @@ static int check_ignore(struct dir_struct *dir,\n>  \t\t\t    pattern->flags & PATTERN_FLAG_NEGATIVE)\n>  \t\t\t\tpattern = NULL;\n>  \t\t}\n> -\t\tif (!quiet && (pattern || show_non_matching))\n> -\t\t\toutput_pattern(pathspec.items[i].original, pattern);\n> +\t\tif (!quiet) {\n> +\t\t\tif (verbose) {\n> +\t\t\t\tif (show_non_matching || pattern)\n> +\t\t\t\t\toutput_pattern(pathspec.items[i].original, pattern);\n> +\t\t\t} else {\n> +\t\t\t\tif (show_non_matching && !pattern)\n> +\t\t\t\t\toutput_pattern(pathspec.items[i].original, pattern);\n> +\t\t\t\tif (!show_non_matching && pattern)\n> +\t\t\t\t\toutput_pattern(pathspec.items[i].original, pattern);\n> +\t\t\t}\n> +\t\t}\n>  \t\tif (pattern)\n>  \t\t\tnum_ignored++;\n>  \t}\n> @@ -175,8 +184,6 @@ int cmd_check_ignore(int argc, const char **argv, const char *prefix)\n>  \t\tif (verbose)\n>  \t\t\tdie(_(\"cannot have both --quiet and --verbose\"));\n>  \t}\n> -\tif (show_non_matching && !verbose)\n> -\t\tdie(_(\"--non-matching is only valid with --verbose\"));\n>  \n>  \t/* read_cache() is only necessary so we can watch out for submodules. */\n>  \tif (!no_index && read_cache() < 0)\n> diff --git a/t/t0008-ignores.sh b/t/t0008-ignores.sh\n> index 5575dade8ee..2ea178797bc 100755\n> --- a/t/t0008-ignores.sh\n> +++ b/t/t0008-ignores.sh\n> @@ -90,7 +90,8 @@ test_check_ignore () {\n>  #   1. with -q / --quiet\n>  #   2. with default verbosity\n>  #   3. with -v / --verbose\n> -#   4. with -v / --verbose, *and* -n / --non-matching\n> +#   4. with -n / --non-matching\n> +#   5. with -v / --verbose, *and* -n / --non-matching\n>  #\n>  # expecting success each time.  Takes advantage of the fact that\n>  # check-ignore --verbose output is the same as normal output except\n> @@ -102,7 +103,7 @@ test_check_ignore () {\n>  # Arguments:\n>  #   - (optional) prereqs for this test, e.g. 'SYMLINKS'\n>  #   - test name\n> -#   - output to expect from the fourth verbosity mode (the output\n> +#   - output to expect from the fifth verbosity mode (the output\n>  #     from the other verbosity modes is automatically inferred\n>  #     from this value)\n>  #   - code to run (should invoke test_check_ignore)\n> @@ -124,6 +125,7 @@ test_expect_success_multiple () {\n>  \n>  \texpect_verbose=$( echo \"$expect_all\" | grep -v '^::\t' )\n>  \texpect=$( echo \"$expect_verbose\" | sed -e 's/.*\t//' )\n> +\texpect_non_matching=$( echo \"$expect_all\" | grep '^::\t' | sed -e 's/.*\t//')\n>  \n>  \ttest_expect_success $prereq \"$testname${no_index_opt:+ with $no_index_opt}\" '\n>  \t\texpect \"$expect\" &&\n> @@ -144,6 +146,17 @@ test_expect_success_multiple () {\n>  \t\tquiet_opt=\n>  \tfi\n>  \n> +\tfor non_matching_opt in '-n' '--non-matching'\n> +\tdo\n> +\t\ttest_code=\"\n> +\t\t\texpect '$expect_non_matching' &&\n> +\t\t\t$code\n> +\t\t\"\n> +\t\topts=\"${no_index_opt:+$no_index_opt }$non_matching_opt\"\n> +\t\ttest_expect_success $prereq \"$testname${opts:+ with $opts}\" \"$test_code\"\n> +\tdone\n> +\tnon_matching_opt=\n> +\n>  \tfor verbose_opt in '-v' '--verbose'\n>  \tdo\n>  \t\tfor non_matching_opt in '' '-n' '--non-matching'\n>\n> base-commit: f9b95943b68b6b8ca5a6072f50a08411c6449b55\n"},{"id":"455931","messageId":"xmqqwneahh8t.fsf@gitster.g","threadId":"57912","inReplyTo":"hl3lllnkPVswb8IZoaMCS62N42epy97_8rLH8qrvSGCbKoovP5_qjtq4nrot5-h-q_7KOu-JpPX4nC0f74BXm6uWdtxosa6z5niHqAJKRUw=@protonmail.com","subject":"Re: [PATCH] check-ignore: --non-matching without --verbose","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-05-24T19:18:10Z","receivedAt":"2022-05-24T19:18:19Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Carl Smedstad <carl.smedstad@protonmail.com> writes:\n\n>> Not commenting on the patch itself, but ...\n>>\n>> > find . |\n>> > git check-ignore --verbose --non-matching |\n>> > grep $'^::\\t' |\n>> > sed -e 's/.*\\t//'\n>>\n>> ... feeding grep output to sed caught my eyes. Isn't that equivalent to\n>>\n>> git ... |\n>> sed -n '/^::\\t/s/.*\\t//p'\n>\n> That is indeed equivalent. TIL about regular-expression addresses in\n> sed, thanks!\n\nI however suspect that these \"\\t\"'s should be spelled out as an\nactual TAB in the final production version for portability.\n\nThanks.\n\n"},{"id":"455935","messageId":"220524.868rqqwx1t.gmgdl@evledraar.gmail.com","threadId":"57912","inReplyTo":"xmqqwneahh8t.fsf@gitster.g","subject":"Re: [PATCH] check-ignore: --non-matching without --verbose","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-05-24T19:26:30Z","receivedAt":"2022-05-24T19:27:49Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Tue, May 24 2022, Junio C Hamano wrote:\n\n> Carl Smedstad <carl.smedstad@protonmail.com> writes:\n>\n>>> Not commenting on the patch itself, but ...\n>>>\n>>> > find . |\n>>> > git check-ignore --verbose --non-matching |\n>>> > grep $'^::\\t' |\n>>> > sed -e 's/.*\\t//'\n>>>\n>>> ... feeding grep output to sed caught my eyes. Isn't that equivalent to\n>>>\n>>> git ... |\n>>> sed -n '/^::\\t/s/.*\\t//p'\n>>\n>> That is indeed equivalent. TIL about regular-expression addresses in\n>> sed, thanks!\n>\n> I however suspect that these \"\\t\"'s should be spelled out as an\n> actual TAB in the final production version for portability.\n\nMake that a \"for sure\", it's a commonly unsupported feature of some\nsed's, it's actually more common that not that it isn't supported. See\n$HT in t4213-log-tabexpand.sh.\n"}]}