git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] git: replace two checks with one not equal check
@ 2023-01-09 18:57 Rose via GitGitGadget
  2024-12-18  0:38 ` [PATCH v2] " AreaZR via GitGitGadget
  0 siblings, 1 reply; 5+ messages in thread
From: Rose via GitGitGadget @ 2023-01-09 18:57 UTC (permalink / raw)
  To: git; +Cc: Rose, Seija Kijin

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 two checks with one not equal check
    
    (version < 2 || version > 2) looks silly considering this is an integer.
    
    Signed-off-by: Seija Kijin doremylover123@gmail.com

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1432%2FAtariDreams%2Fversion-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1432/AtariDreams/version-v1
Pull-Request: https://github.com/git/git/pull/1432

 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 0e0b9fb95bc..ae5cbfdc407 100644
--- a/builtin/show-index.c
+++ b/builtin/show-index.c
@@ -38,7 +38,7 @@ int cmd_show_index(int argc, const char **argv, const char *prefix)
 		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 c0d7dd93f46..428f572a263 100644
--- a/packfile.c
+++ b/packfile.c
@@ -121,7 +121,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: a38d39a4c50d1275833aba54c4dbdfce9e2e9ca1
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2] git: replace two checks with one not equal check
  2023-01-09 18:57 [PATCH] git: replace two checks with one not equal check Rose via GitGitGadget
@ 2024-12-18  0:38 ` AreaZR via GitGitGadget
  2024-12-18  0:50   ` [PATCH v3] git: replace greater-than and less-than " AreaZR via GitGitGadget
  0 siblings, 1 reply; 5+ messages in thread
From: AreaZR via GitGitGadget @ 2024-12-18  0:38 UTC (permalink / raw)
  To: git; +Cc: AreaZR, Seija Kijin

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 two checks with one not equal check
    
    (version < 2 || version > 2) looks silly considering this is an integer.
    
    Signed-off-by: Seija Kijin doremylover123@gmail.com

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1432%2FAreaZR%2Fversion-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1432/AreaZR/version-v2
Pull-Request: https://github.com/git/git/pull/1432

Range-diff vs v1:

 1:  e9172aea097 ! 1:  07e0d614c21 git: replace two checks with one not equal check
     @@ Commit message
          Signed-off-by: Seija Kijin <doremylover123@gmail.com>
      
       ## builtin/show-index.c ##
     -@@ builtin/show-index.c: int cmd_show_index(int argc, const char **argv, const char *prefix)
     +@@ builtin/show-index.c: int cmd_show_index(int argc,
       		die("unable to read header");
       	if (top_index[0] == htonl(PACK_IDX_SIGNATURE)) {
       		version = ntohl(top_index[1]);


 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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3] git: replace greater-than and less-than checks with one not equal check
  2024-12-18  0:38 ` [PATCH v2] " AreaZR via GitGitGadget
@ 2024-12-18  0:50   ` AreaZR via GitGitGadget
  2024-12-18  2:44     ` [PATCH v4] " AreaZR via GitGitGadget
  0 siblings, 1 reply; 5+ messages in thread
From: AreaZR via GitGitGadget @ 2024-12-18  0:50 UTC (permalink / raw)
  To: git; +Cc: AreaZR, Seija Kijin

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 chain of greater-than and less-than checks with one not
    equal check
    
    (version < 2 || version > 2) looks silly considering this is an integer.
    
    Signed-off-by: Seija Kijin doremylover123@gmail.com

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1432%2FAreaZR%2Fversion-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1432/AreaZR/version-v3
Pull-Request: https://github.com/git/git/pull/1432

Range-diff vs v2:

 1:  07e0d614c21 ! 1:  322d04519d5 git: replace two checks with one not equal check
     @@ Metadata
      Author: Seija Kijin <doremylover123@gmail.com>
      
       ## Commit message ##
     -    git: replace two checks with one not equal check
     +    git: replace greater-than and less-than checks with one not equal check
      
          (version < 2 || version > 2) looks silly
          considering this is an integer.


 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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v4] git: replace greater-than and less-than checks with one not equal check
  2024-12-18  0:50   ` [PATCH v3] git: replace greater-than and less-than " AreaZR via GitGitGadget
@ 2024-12-18  2:44     ` AreaZR via GitGitGadget
  2024-12-18 15:39       ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: AreaZR via GitGitGadget @ 2024-12-18  2:44 UTC (permalink / raw)
  To: git; +Cc: AreaZR, Seija Kijin

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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v4] git: replace greater-than and less-than checks with one not equal check
  2024-12-18  2:44     ` [PATCH v4] " AreaZR via GitGitGadget
@ 2024-12-18 15:39       ` Junio C Hamano
  0 siblings, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2024-12-18 15:39 UTC (permalink / raw)
  To: AreaZR via GitGitGadget; +Cc: git, AreaZR, Seija Kijin

"AreaZR via GitGitGadget" <gitgitgadget@gmail.com> writes:

>  	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");

I am of two minds.  If the code never evolves and we will never
support anything other than version #2, your rewrite certainly makes
it easier to read.  On the other hand, if we plan to ever learn to
grok versions #3 and later, the original would be easier to se what
is going on, i.e.

		if (version < VERSION_LB || VERSION_UB < version)
			die("version out of bounds");

and the code as written happens to have "2" as both lower- and
upper-bound.

Of course when we do introduce version #3, this line must be updated
anyway, but the final form would be as we have it with the second
"2" replaced with "3", so leaving it in the current shape may be
easier for the developer doing that work.

So I do not know if the proposed change is an improvement for the
longer term.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-12-18 15:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-09 18:57 [PATCH] git: replace two checks with one not equal check Rose via GitGitGadget
2024-12-18  0:38 ` [PATCH v2] " AreaZR via GitGitGadget
2024-12-18  0:50   ` [PATCH v3] git: replace greater-than and less-than " AreaZR via GitGitGadget
2024-12-18  2:44     ` [PATCH v4] " AreaZR via GitGitGadget
2024-12-18 15:39       ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).