{"thread":{"id":"59061","subject":"[PATCH] git: replace two checks with one not equal check","startedAt":"2023-01-09T18:57:09Z","lastAt":"2024-12-18T15:39:51Z","messageCount":5,"participants":["Rose via GitGitGadget","AreaZR via GitGitGadget","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"469998","messageId":"pull.1432.git.git.1673290620410.gitgitgadget@gmail.com","threadId":"59061","inReplyTo":null,"subject":"[PATCH] git: replace two checks with one not equal check","fromName":"Rose via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2023-01-09T18:57:00Z","receivedAt":"2023-01-09T18:57:09Z","isPatch":true,"sender":{"key":"ckelsch@jgrcpa.com","avatar":null},"body":"From: Seija Kijin <doremylover123@gmail.com>\n\n(version < 2 || version > 2) looks silly\nconsidering this is an integer.\n\nSigned-off-by: Seija Kijin <doremylover123@gmail.com>\n---\n    git: replace two checks with one not equal check\n    \n    (version < 2 || version > 2) looks silly considering this is an integer.\n    \n    Signed-off-by: Seija Kijin doremylover123@gmail.com\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1432%2FAtariDreams%2Fversion-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1432/AtariDreams/version-v1\nPull-Request: https://github.com/git/git/pull/1432\n\n builtin/show-index.c | 2 +-\n packfile.c           | 2 +-\n 2 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/show-index.c b/builtin/show-index.c\nindex 0e0b9fb95bc..ae5cbfdc407 100644\n--- a/builtin/show-index.c\n+++ b/builtin/show-index.c\n@@ -38,7 +38,7 @@ int cmd_show_index(int argc, const char **argv, const char *prefix)\n \t\tdie(\"unable to read header\");\n \tif (top_index[0] == htonl(PACK_IDX_SIGNATURE)) {\n \t\tversion = ntohl(top_index[1]);\n-\t\tif (version < 2 || version > 2)\n+\t\tif (version != 2)\n \t\t\tdie(\"unknown index version\");\n \t\tif (fread(top_index, 256 * 4, 1, stdin) != 1)\n \t\t\tdie(\"unable to read index\");\ndiff --git a/packfile.c b/packfile.c\nindex c0d7dd93f46..428f572a263 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -121,7 +121,7 @@ int load_idx(const char *path, const unsigned int hashsz, void *idx_map,\n \n \tif (hdr->idx_signature == htonl(PACK_IDX_SIGNATURE)) {\n \t\tversion = ntohl(hdr->idx_version);\n-\t\tif (version < 2 || version > 2)\n+\t\tif (version != 2)\n \t\t\treturn error(\"index file %s is version %\"PRIu32\n \t\t\t\t     \" and is not supported by this binary\"\n \t\t\t\t     \" (try upgrading GIT to a newer version)\",\n\nbase-commit: a38d39a4c50d1275833aba54c4dbdfce9e2e9ca1\n-- \ngitgitgadget\n"},{"id":"509252","messageId":"pull.1432.v2.git.git.1734482334390.gitgitgadget@gmail.com","threadId":"59061","inReplyTo":"pull.1432.git.git.1673290620410.gitgitgadget@gmail.com","subject":"[PATCH v2] git: replace two checks with one not equal check","fromName":"AreaZR via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2024-12-18T00:38:54Z","receivedAt":"2024-12-18T00:38:57Z","isPatch":true,"sender":{"key":"name:AreaZR","avatar":null},"body":"From: Seija Kijin <doremylover123@gmail.com>\n\n(version < 2 || version > 2) looks silly\nconsidering this is an integer.\n\nSigned-off-by: Seija Kijin <doremylover123@gmail.com>\n---\n    git: replace two checks with one not equal check\n    \n    (version < 2 || version > 2) looks silly considering this is an integer.\n    \n    Signed-off-by: Seija Kijin doremylover123@gmail.com\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1432%2FAreaZR%2Fversion-v2\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1432/AreaZR/version-v2\nPull-Request: https://github.com/git/git/pull/1432\n\nRange-diff vs v1:\n\n 1:  e9172aea097 ! 1:  07e0d614c21 git: replace two checks with one not equal check\n     @@ Commit message\n          Signed-off-by: Seija Kijin <doremylover123@gmail.com>\n      \n       ## builtin/show-index.c ##\n     -@@ builtin/show-index.c: int cmd_show_index(int argc, const char **argv, const char *prefix)\n     +@@ builtin/show-index.c: int cmd_show_index(int argc,\n       \t\tdie(\"unable to read header\");\n       \tif (top_index[0] == htonl(PACK_IDX_SIGNATURE)) {\n       \t\tversion = ntohl(top_index[1]);\n\n\n builtin/show-index.c | 2 +-\n packfile.c           | 2 +-\n 2 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/show-index.c b/builtin/show-index.c\nindex f164c01bbea..5fb71a1c425 100644\n--- a/builtin/show-index.c\n+++ b/builtin/show-index.c\n@@ -44,7 +44,7 @@ int cmd_show_index(int argc,\n \t\tdie(\"unable to read header\");\n \tif (top_index[0] == htonl(PACK_IDX_SIGNATURE)) {\n \t\tversion = ntohl(top_index[1]);\n-\t\tif (version < 2 || version > 2)\n+\t\tif (version != 2)\n \t\t\tdie(\"unknown index version\");\n \t\tif (fread(top_index, 256 * 4, 1, stdin) != 1)\n \t\t\tdie(\"unable to read index\");\ndiff --git a/packfile.c b/packfile.c\nindex 9c4bd81a8c7..de0662b2353 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -114,7 +114,7 @@ int load_idx(const char *path, const unsigned int hashsz, void *idx_map,\n \n \tif (hdr->idx_signature == htonl(PACK_IDX_SIGNATURE)) {\n \t\tversion = ntohl(hdr->idx_version);\n-\t\tif (version < 2 || version > 2)\n+\t\tif (version != 2)\n \t\t\treturn error(\"index file %s is version %\"PRIu32\n \t\t\t\t     \" and is not supported by this binary\"\n \t\t\t\t     \" (try upgrading GIT to a newer version)\",\n\nbase-commit: 063bcebf0c917140ca0e705cbe0fdea127e90086\n-- \ngitgitgadget\n"},{"id":"509255","messageId":"pull.1432.v3.git.git.1734483016515.gitgitgadget@gmail.com","threadId":"59061","inReplyTo":"pull.1432.v2.git.git.1734482334390.gitgitgadget@gmail.com","subject":"[PATCH v3] git: replace greater-than and less-than checks with one not equal check","fromName":"AreaZR via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2024-12-18T00:50:16Z","receivedAt":"2024-12-18T00:50:19Z","isPatch":true,"sender":{"key":"name:AreaZR","avatar":null},"body":"From: Seija Kijin <doremylover123@gmail.com>\n\n(version < 2 || version > 2) looks silly\nconsidering this is an integer.\n\nSigned-off-by: Seija Kijin <doremylover123@gmail.com>\n---\n    git: replace chain of greater-than and less-than checks with one not\n    equal check\n    \n    (version < 2 || version > 2) looks silly considering this is an integer.\n    \n    Signed-off-by: Seija Kijin doremylover123@gmail.com\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1432%2FAreaZR%2Fversion-v3\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1432/AreaZR/version-v3\nPull-Request: https://github.com/git/git/pull/1432\n\nRange-diff vs v2:\n\n 1:  07e0d614c21 ! 1:  322d04519d5 git: replace two checks with one not equal check\n     @@ Metadata\n      Author: Seija Kijin <doremylover123@gmail.com>\n      \n       ## Commit message ##\n     -    git: replace two checks with one not equal check\n     +    git: replace greater-than and less-than checks with one not equal check\n      \n          (version < 2 || version > 2) looks silly\n          considering this is an integer.\n\n\n builtin/show-index.c | 2 +-\n packfile.c           | 2 +-\n 2 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/show-index.c b/builtin/show-index.c\nindex f164c01bbea..5fb71a1c425 100644\n--- a/builtin/show-index.c\n+++ b/builtin/show-index.c\n@@ -44,7 +44,7 @@ int cmd_show_index(int argc,\n \t\tdie(\"unable to read header\");\n \tif (top_index[0] == htonl(PACK_IDX_SIGNATURE)) {\n \t\tversion = ntohl(top_index[1]);\n-\t\tif (version < 2 || version > 2)\n+\t\tif (version != 2)\n \t\t\tdie(\"unknown index version\");\n \t\tif (fread(top_index, 256 * 4, 1, stdin) != 1)\n \t\t\tdie(\"unable to read index\");\ndiff --git a/packfile.c b/packfile.c\nindex 9c4bd81a8c7..de0662b2353 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -114,7 +114,7 @@ int load_idx(const char *path, const unsigned int hashsz, void *idx_map,\n \n \tif (hdr->idx_signature == htonl(PACK_IDX_SIGNATURE)) {\n \t\tversion = ntohl(hdr->idx_version);\n-\t\tif (version < 2 || version > 2)\n+\t\tif (version != 2)\n \t\t\treturn error(\"index file %s is version %\"PRIu32\n \t\t\t\t     \" and is not supported by this binary\"\n \t\t\t\t     \" (try upgrading GIT to a newer version)\",\n\nbase-commit: 063bcebf0c917140ca0e705cbe0fdea127e90086\n-- \ngitgitgadget\n"},{"id":"509267","messageId":"pull.1432.v4.git.git.1734489859673.gitgitgadget@gmail.com","threadId":"59061","inReplyTo":"pull.1432.v3.git.git.1734483016515.gitgitgadget@gmail.com","subject":"[PATCH v4] git: replace greater-than and less-than checks with one not equal check","fromName":"AreaZR via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2024-12-18T02:44:19Z","receivedAt":"2024-12-18T02:44:22Z","isPatch":true,"sender":{"key":"name:AreaZR","avatar":null},"body":"From: Seija Kijin <doremylover123@gmail.com>\n\n(version < 2 || version > 2) looks silly\nconsidering this is an integer.\n\nSigned-off-by: Seija Kijin <doremylover123@gmail.com>\n---\n    git: replace greater-than and less-than checks with one not equal check\n    \n    (version < 2 || version > 2) looks silly considering this is an integer.\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1432%2FAreaZR%2Fversion-v4\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1432/AreaZR/version-v4\nPull-Request: https://github.com/git/git/pull/1432\n\nRange-diff vs v3:\n\n 1:  322d04519d5 = 1:  503f6635522 git: replace greater-than and less-than checks with one not equal check\n\n\n builtin/show-index.c | 2 +-\n packfile.c           | 2 +-\n 2 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/show-index.c b/builtin/show-index.c\nindex f164c01bbea..5fb71a1c425 100644\n--- a/builtin/show-index.c\n+++ b/builtin/show-index.c\n@@ -44,7 +44,7 @@ int cmd_show_index(int argc,\n \t\tdie(\"unable to read header\");\n \tif (top_index[0] == htonl(PACK_IDX_SIGNATURE)) {\n \t\tversion = ntohl(top_index[1]);\n-\t\tif (version < 2 || version > 2)\n+\t\tif (version != 2)\n \t\t\tdie(\"unknown index version\");\n \t\tif (fread(top_index, 256 * 4, 1, stdin) != 1)\n \t\t\tdie(\"unable to read index\");\ndiff --git a/packfile.c b/packfile.c\nindex 9c4bd81a8c7..de0662b2353 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -114,7 +114,7 @@ int load_idx(const char *path, const unsigned int hashsz, void *idx_map,\n \n \tif (hdr->idx_signature == htonl(PACK_IDX_SIGNATURE)) {\n \t\tversion = ntohl(hdr->idx_version);\n-\t\tif (version < 2 || version > 2)\n+\t\tif (version != 2)\n \t\t\treturn error(\"index file %s is version %\"PRIu32\n \t\t\t\t     \" and is not supported by this binary\"\n \t\t\t\t     \" (try upgrading GIT to a newer version)\",\n\nbase-commit: 063bcebf0c917140ca0e705cbe0fdea127e90086\n-- \ngitgitgadget\n"},{"id":"509304","messageId":"xmqqjzbxt2yi.fsf@gitster.g","threadId":"59061","inReplyTo":"pull.1432.v4.git.git.1734489859673.gitgitgadget@gmail.com","subject":"Re: [PATCH v4] git: replace greater-than and less-than checks with one not equal check","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-12-18T15:39:49Z","receivedAt":"2024-12-18T15:39:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"AreaZR via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n>  \tif (top_index[0] == htonl(PACK_IDX_SIGNATURE)) {\n>  \t\tversion = ntohl(top_index[1]);\n> -\t\tif (version < 2 || version > 2)\n> +\t\tif (version != 2)\n>  \t\t\tdie(\"unknown index version\");\n\nI am of two minds.  If the code never evolves and we will never\nsupport anything other than version #2, your rewrite certainly makes\nit easier to read.  On the other hand, if we plan to ever learn to\ngrok versions #3 and later, the original would be easier to se what\nis going on, i.e.\n\n\t\tif (version < VERSION_LB || VERSION_UB < version)\n\t\t\tdie(\"version out of bounds\");\n\nand the code as written happens to have \"2\" as both lower- and\nupper-bound.\n\nOf course when we do introduce version #3, this line must be updated\nanyway, but the final form would be as we have it with the second\n\"2\" replaced with \"3\", so leaving it in the current shape may be\neasier for the developer doing that work.\n\nSo I do not know if the proposed change is an improvement for the\nlonger term.\n"}]}