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

[PATCH v4] git: replace greater-than and less-than checks with one not equal check

From
AGAreaZR via GitGitGadget <gitgitgadget@gmail.com>
Date
Dec 18, 2024, 02:44 UTC
Message-ID
<pull.1432.v4.git.git.1734489859673.gitgitgadget@gmail.com>
In-Reply-To
<pull.1432.v3.git.git.1734483016515.gitgitgadget@gmail.com>
From: Seija Kijin <doremylover123@gmail.com>

(version < 2 || version > 2) looks silly considering this is an integer.

Signed-off-by: Seija Kijin <doremylover123@gmail.com>
---
    git: replace greater-than and less-than checks with one not equal check
    
    (version < 2 || version > 2) looks silly considering this is an integer.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1432%2FAreaZR%2Fversion-v4
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1432/AreaZR/version-v4
Pull-Request: https://github.com/git/git/pull/1432
Range-diff vs v3:
 1:  322d04519d5 = 1:  503f6635522 git: replace greater-than and less-than checks with one not equal check
 builtin/show-index.c | 2 +-
 packfile.c           | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/builtin/show-index.c b/builtin/show-index.c
index f164c01bbea..5fb71a1c425 100644
--- a/builtin/show-index.c
+++ b/builtin/show-index.c
@@ -44,7 +44,7 @@ int cmd_show_index(int argc,
 		die("unable to read header");
 	if (top_index[0] == htonl(PACK_IDX_SIGNATURE)) {
 		version = ntohl(top_index[1]);
-		if (version < 2 || version > 2)
+		if (version != 2)
 			die("unknown index version");
 		if (fread(top_index, 256 * 4, 1, stdin) != 1)
 			die("unable to read index");
diff --git a/packfile.c b/packfile.c
index 9c4bd81a8c7..de0662b2353 100644
--- a/packfile.c
+++ b/packfile.c
@@ -114,7 +114,7 @@ int load_idx(const char *path, const unsigned int hashsz, void *idx_map,
 
 	if (hdr->idx_signature == htonl(PACK_IDX_SIGNATURE)) {
 		version = ntohl(hdr->idx_version);
-		if (version < 2 || version > 2)
+		if (version != 2)
 			return error("index file %s is version %"PRIu32
 				     " and is not supported by this binary"
 				     " (try upgrading GIT to a newer version)",

base-commit: 063bcebf0c917140ca0e705cbe0fdea127e90086
-- 
gitgitgadget
Previous: AreaZR via GitGitGadgetNext: Junio C Hamano
Message 4 of 5 in “git: replace two checks with one not equal check”
  1. git: replace two checks with one not equal checkRose via GitGitGadget, Jan 9, 2023
  2. git: replace two checks with one not equal checkAreaZR via GitGitGadget, Dec 18, 2024
  3. git: replace greater-than and less-than checks with one not equal checkAreaZR via GitGitGadget, Dec 18, 2024
  4. git: replace greater-than and less-than checks with one not equal checkAreaZR via GitGitGadget, Dec 18, 2024
  5. Junio C HamanoDec 18, 2024

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.