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

Re: [PATCH 2/2] add -i: default to the built-in implementation

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 2, 2021, 16:58 UTC
Message-ID
<xmqq5ys7vt8t.fsf@gitster.g>
In-Reply-To
<nycvar.QRO.7.76.6.2112021557530.63@tvgsbejvaqbjf.bet>
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
Show 17 quoted lines
>> > +	if (use_builtin_add_i < 0 &&
>> > +	    git_config_get_bool("add.interactive.usebuiltin",
>> > +				&use_builtin_add_i))
>> > +		use_builtin_add_i = 1;
>> >   -	if (use_builtin_add_i == 1) {
>> > +	if (use_builtin_add_i != 0) {
>>
>> This could be simplified to "if (use_builtin_add_i)" but don't re-roll just
>> for that
>
> I was actually considering this, given that Git's coding practice suggests
> precisely the form you suggested.
>
> However, in this instance I found that form misleading: it would read to
> me as if `use_builtin_add_i` was a Boolean. But it is a tristate, it can
> also be `-1` ("undecided"). And I wanted to express "if this is not set to
> `false` specifically", therefore I ended up with my proposal.

I do not think that line of logic is sensible. The variable starts its life as a tristate (i.e. not just bool but can be unknown), and the four new lines above the conditional the patch adds is exactly about getting rid of the unknown-ness and turning it into a known boolean. After that happens, the variable can safely be used as a boolean. In fact, I view the four lines before it is exactly to allow us to do so.

Writing "if not zero" implies that the variable can have a non-zero value that is still "unknown" at this point in the code that has to be defaulted to "true", which would mean that the "if unset, read the config, and if that fails, default to true" logic above is not doing its job. That is a false impression that misleads readers of the code.

So, I would say this conditional just should treat the variable as a simple boolean.

Previous: Johannes SchindelinNext: Ramsay Jones
Message 8 of 23 in “Use the built-in implementation of the interactive add command by default”
  1. 0/2 Use the built-in implementation of the interactive add command by defaultJohannes Schindelin via GitGitGadget, Nov 30, 2021
  2. 1/2 t2016: require the PERL prereq only when necessaryJohannes Schindelin via GitGitGadget, Nov 30, 2021
  3. Junio C HamanoDec 1, 2021
  4. Johannes SchindelinDec 2, 2021
  5. 2/2 add -i: default to the built-in implementationJohannes Schindelin via GitGitGadget, Nov 30, 2021
  6. Phillip WoodDec 1, 2021
  7. Johannes SchindelinDec 2, 2021
  8. Junio C HamanoDec 2, 2021
  9. Ramsay JonesDec 2, 2021
  10. Johannes SchindelinDec 10, 2021
  11. Ævar Arnfjörð BjarmasonDec 1, 2021
  12. Junio C HamanoDec 1, 2021
  13. Junio C HamanoDec 1, 2021
  14. Johannes SchindelinDec 2, 2021
  15. fixup! add -i: default to the built-in implementationJunio C Hamano, Dec 9, 2021
  16. Johannes SchindelinDec 10, 2021
  17. Jeff KingNov 30, 2021
  18. Junio C HamanoNov 30, 2021
  19. Ævar Arnfjörð BjarmasonDec 1, 2021
  20. Carlo ArenasDec 1, 2021
  21. Johannes SchindelinDec 2, 2021
  22. Philippe BlainDec 3, 2021
  23. Johannes SchindelinDec 6, 2021

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.