Re: [PATCH] mergetool: new config guiDefault supports auto-toggling gui by DISPLAY
- From
Tao Klerks <tao@klerks.biz>
- Date
- Oct 14, 2022, 12:32 UTC
- Message-ID
- <CAPMMpoiwnLyqzBBubkgSpjyJQqSeEVdoZy72FAwGDbMgg9UXxg@mail.gmail.com>
- In-Reply-To
- <xmqqsfjqbwil.fsf@gitster.g>
On Fri, Oct 14, 2022 at 11:11 AM Junio C Hamano <gitster@pobox.com> wrote:
Show 18 quoted lines
> > Tao Klerks <tao@klerks.biz> writes: > > > 1. Why add an OPT_CALLBACK_F arg handler, rather than keeping a simple > > OPT_BOOL arg type? > > Because OPT_BOOL always overwrites with either true or false, so in > > order to have use_gui_tool retain its "_BY_CONFIG" value in the > > absence of an arg, the explicit arg handler function is required. > > That is exactly why you want to initialize the variable to something > other than 0 or 1 (say "-1") and use that as "not explicitly > specified from the command line" aka _BY_CONFIG value, isn't it? > > And once you do so, you do not need callback and you do not need > enum. The original "int" can take tri-state, (unspecified = -1, > false = 0, true = 1). > > Am I missing something?
Heh, I guess one of us must be, and it's probably me :)
My understanding, from ad-hoc testing, is that using OPT_BOOL causes the target variable ("use_gui_tool" in this case) to *always* be set to either "1" or "0", regardless of whether the user sets the main flag, the --no form of the flag, or sets nothing at all. As far as I can tell, OPT_BOOL never leaves the original value, so it cannot be used to track tri-state "true, false or not specified" logic. Maybe I made a mistake somewhere, and that's not really or always how it behaves.
I can re-test, and/or try to dig into the option parsing logic to understand how it works - the time I tried, I got hopelessly lost and was relieved to find that OPT_CALLBACK_F existed and seemed to be used for exactly these kinds of use cases.