From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
git@vger.kernel.org, "Lin Sun" <lin.sun@zoom.us>,
"Đoàn Trần Công Danh" <congdanhqx@gmail.com>,
"David Aguilar" <davvid@gmail.com>
Subject: Re: [PATCH 4/5] config.c: add a "tristate" helper
Date: Fri, 9 Apr 2021 21:23:16 -0400 [thread overview]
Message-ID: <YHD+BMo35krbH9rx@coredump.intra.peff.net> (raw)
In-Reply-To: <xmqqv98vm7lt.fsf@gitster.g>
On Fri, Apr 09, 2021 at 03:11:10PM -0700, Junio C Hamano wrote:
> > I dunno. That would probably be hard to represent via "git config
> > --type". And some callers probably do care about "auto" versus "true".
>
> It would work well for codepaths where computing the default value
> is cheap (or even possible).
>
> I think the point of using "auto" is to delay the decision as late
> as possible. E.g. in-core parsed config and attribute may still
> want to stay "auto", until we actually get our hands on the blob
> contents to see if it is binary, until we know how heavily loaded
> the system is, until we know isatty(1), etc. Some are cheap to
> compute in advance, some are expensive and impossible until we meet
> the data.
Hmm, yeah, that's the "do care about auto versus true" thing.
> So I still think the canonical use pattern for the "auto" thing is
>
> is_frotz = git_parse_bool_or_auto(value);
>
> ... arbitrary number of things can happen here
> ... the above may even be done in a git_config()
> ... callback, and is_frotz may not even be used.
>
> if (is_frotz == AUTO)
> is_frotz = auto_detect_frotz();
>
> if (is_frotz)
> ...; /* do the frotz thing */
> else
> ...; /* do the non-frotz thing */
That makes sense. Usually we represent "undecided" in such a tristate
with -1, so something that returned -1/0/1 would feel very natural to me
(and probably wouldn't need symbolic constants even). But -1 is also
error.
So a function like:
int git_parse_tristate(const char *value, int *out);
which returned success/error via its return value, and put the value
into "out" would feel pretty natural to me.
I dunno. I admit I don't care _that_ much, but somehow Ævar's series
have a way of sniping me into responding anyway. :)
-Peff
next prev parent reply other threads:[~2021-04-10 1:23 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-08 13:34 [PATCH 0/5] config: support --type=bool-or-auto for "tristate" parsing Ævar Arnfjörð Bjarmason
2021-04-08 13:34 ` [PATCH 1/5] config.c: add a comment about why value=NULL is true Ævar Arnfjörð Bjarmason
2021-04-08 18:10 ` Junio C Hamano
2021-04-08 13:34 ` [PATCH 2/5] config tests: test for --bool-or-str Ævar Arnfjörð Bjarmason
2021-04-08 18:21 ` Junio C Hamano
2021-04-08 23:11 ` Ævar Arnfjörð Bjarmason
2021-04-08 13:34 ` [PATCH 3/5] git-config: document --bool-or-str and --type=bool-or-str Ævar Arnfjörð Bjarmason
2021-04-08 18:22 ` Junio C Hamano
2021-04-08 13:34 ` [PATCH 4/5] config.c: add a "tristate" helper Ævar Arnfjörð Bjarmason
2021-04-08 18:33 ` Junio C Hamano
2021-04-08 23:23 ` Ævar Arnfjörð Bjarmason
2021-04-08 23:51 ` Junio C Hamano
2021-04-09 1:33 ` Ævar Arnfjörð Bjarmason
2021-04-09 12:53 ` Junio C Hamano
2021-04-08 23:54 ` Junio C Hamano
2021-04-09 20:05 ` Jeff King
2021-04-09 22:11 ` Junio C Hamano
2021-04-10 1:23 ` Jeff King [this message]
2021-04-10 1:43 ` Junio C Hamano
2021-04-08 13:34 ` [PATCH 5/5] config: add --type=bool-or-auto switch Ævar Arnfjörð Bjarmason
2021-04-08 18:36 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YHD+BMo35krbH9rx@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=avarab@gmail.com \
--cc=congdanhqx@gmail.com \
--cc=davvid@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=lin.sun@zoom.us \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).