{"thread":{"id":"58978","subject":"[PATCH] Remove redundant double exclamation points","startedAt":"2022-12-19T14:12:50Z","lastAt":"2022-12-20T00:51:03Z","messageCount":3,"participants":["Rose via GitGitGadget","Ævar Arnfjörð Bjarmason","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"469286","messageId":"pull.1401.git.git.1671459163559.gitgitgadget@gmail.com","threadId":"58978","inReplyTo":null,"subject":"[PATCH] Remove redundant double exclamation points","fromName":"Rose via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2022-12-19T14:12:43Z","receivedAt":"2022-12-19T14:12:50Z","isPatch":true,"sender":{"key":"ckelsch@jgrcpa.com","avatar":null},"body":"From: Seija Kijin <doremylover123@gmail.com>\n\nS_ISDIR is a macro that involves a \"==\" comparison.\n\nThis means the !! is redundant and not needed.\n\nSigned-off-by: Seija Kijin <doremylover123@gmail.com>\n---\n    Remove redundant double exclamation points\n    \n    S_ISDIR is a macro that involves a \"==\" comparison.\n    \n    This means the !! is redundant and not needed.\n    \n    Signed-off-by: Seija Kijin doremylover123@gmail.com\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1401%2FAtariDreams%2FIS_DIR-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1401/AtariDreams/IS_DIR-v1\nPull-Request: https://github.com/git/git/pull/1401\n\n tree-walk.c | 9 ++++-----\n 1 file changed, 4 insertions(+), 5 deletions(-)\n\ndiff --git a/tree-walk.c b/tree-walk.c\nindex 74f4d710e8f..6b51d27ccb2 100644\n--- a/tree-walk.c\n+++ b/tree-walk.c\n@@ -1040,9 +1040,9 @@ static enum interesting do_match(struct index_state *istate,\n \t\t    ps->max_depth == -1)\n \t\t\treturn all_entries_interesting;\n \t\treturn within_depth(base->buf + base_offset, baselen,\n-\t\t\t\t    !!S_ISDIR(entry->mode),\n-\t\t\t\t    ps->max_depth) ?\n-\t\t\tentry_interesting : entry_not_interesting;\n+\t\t\t\t    S_ISDIR(entry->mode), ps->max_depth) ?\n+\t\t\t       entry_interesting :\n+\t\t\t       entry_not_interesting;\n \t}\n \n \tpathlen = tree_entry_len(entry);\n@@ -1073,8 +1073,7 @@ static enum interesting do_match(struct index_state *istate,\n \n \t\t\tif (within_depth(base_str + matchlen + 1,\n \t\t\t\t\t baselen - matchlen - 1,\n-\t\t\t\t\t !!S_ISDIR(entry->mode),\n-\t\t\t\t\t ps->max_depth))\n+\t\t\t\t\t S_ISDIR(entry->mode), ps->max_depth))\n \t\t\t\tgoto interesting;\n \t\t\telse\n \t\t\t\treturn entry_not_interesting;\n\nbase-commit: 7c2ef319c52c4997256f5807564523dfd4acdfc7\n-- \ngitgitgadget\n"},{"id":"469296","messageId":"221219.868rj3za6s.gmgdl@evledraar.gmail.com","threadId":"58978","inReplyTo":"pull.1401.git.git.1671459163559.gitgitgadget@gmail.com","subject":"Re: [PATCH] Remove redundant double exclamation points","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-12-19T15:19:23Z","receivedAt":"2022-12-19T15:26:43Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Mon, Dec 19 2022, Rose via GitGitGadget wrote:\n\n> From: Seija Kijin <doremylover123@gmail.com>\n>\n> S_ISDIR is a macro that involves a \"==\" comparison.\n\nIt does? The POSIX standard\n(https://pubs.opengroup.org/onlinepubs/009604499/basedefs/sys/stat.h.html)\nsays:\n\n\tThe following macros shall be provided to test whether a file is\n\tof the specified type. The value m supplied to the macros is the\n\tvalue of st_mode from a stat structure. The macro shall evaluate\n\tto a non-zero value if the test is true; 0 if the test is false.\n\nThe \"non-zero\" there seems to intentionally leave open that this may be\ndefined e.g. as via a \"&\" test, as opposed to \"==\" which according to\nC99's 6.5.9.3 says:\n\n\tThe == (equal to) and != (not equal to) operators are analogous\n\tto the relational operators except for their lower\n\tprecedence.90) Each of the operators yields 1 if the specified\n\trelation is true and 0 if it is false. The result has type\n\tint. For any pair of operands, exactly one of the relations is\n\ttrue.\n\n> This means the !! is redundant and not needed.\n\nI think you're therefore introducing a bug here, this may work on your\nplatform, but we have no guarantee that it'll work elsewhere.\n\nI thought that it probably wouldn't matter, as we'd treat the argument\nas a boolean, but we don't. In within_depth() we proceed to use the\npassed-in 3rd argument (depth) as a counter, so it really does matter if\nit's 0, 1, or other non-zero.\n\n>  tree-walk.c | 9 ++++-----\n>  1 file changed, 4 insertions(+), 5 deletions(-)\n>\n> diff --git a/tree-walk.c b/tree-walk.c\n> index 74f4d710e8f..6b51d27ccb2 100644\n> --- a/tree-walk.c\n> +++ b/tree-walk.c\n> @@ -1040,9 +1040,9 @@ static enum interesting do_match(struct index_state *istate,\n>  \t\t    ps->max_depth == -1)\n>  \t\t\treturn all_entries_interesting;\n>  \t\treturn within_depth(base->buf + base_offset, baselen,\n> -\t\t\t\t    !!S_ISDIR(entry->mode),\n> -\t\t\t\t    ps->max_depth) ?\n> -\t\t\tentry_interesting : entry_not_interesting;\n> +\t\t\t\t    S_ISDIR(entry->mode), ps->max_depth) ?\n> +\t\t\t       entry_interesting :\n> +\t\t\t       entry_not_interesting;\n>  \t}\n>  \n>  \tpathlen = tree_entry_len(entry);\n\nAside from whether or not this is a bug, could you please submit\nproposed refactorings of the git project via coccinelle patches if\npossible (as I suggested to you before).\n\nI realize that it has a slight learning curve, but it makes writing &\nmaintaining these so much easier, and it'll fix (mis)uses going forward,\nnot just as a one-off.\n\nSo, as an example (and assuming this wasn't buggy), you'd do that in\nthis case as e.g. (untested, but you can see similar syntax in our\nexisting *.cocci files):\n\t\n\t@@\n\t@@\n\t- !!\n\t(\n\tS_ISDIR\n\t|\n\tS_ISFIFO\n        // |\n        // we'd continue to list the rest here...\n\t)\n\t  (...)\n"},{"id":"469335","messageId":"xmqqzgbizymk.fsf@gitster.g","threadId":"58978","inReplyTo":"221219.868rj3za6s.gmgdl@evledraar.gmail.com","subject":"Re: [PATCH] Remove redundant double exclamation points","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-12-20T00:50:59Z","receivedAt":"2022-12-20T00:51:03Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:\n\n> I think you're therefore introducing a bug here, this may work on your\n> platform, but we have no guarantee that it'll work elsewhere.\n\nThanks, well analysed.\n\n"}]}