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

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

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 18, 2024, 15:39 UTC
Message-ID
<xmqqjzbxt2yi.fsf@gitster.g>
In-Reply-To
<pull.1432.v4.git.git.1734489859673.gitgitgadget@gmail.com>
"AreaZR via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 5 quoted lines
>  	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.

Previous: AreaZR via GitGitGadget
Message 5 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.