From: Jeff King <peff@peff.net>
To: Markus Heidelberg <markus.heidelberg@web.de>
Cc: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>,
"Junio C Hamano" <gitster@pobox.com>,
git@vger.kernel.org
Subject: Re: [PATCH 1/2] handle color.ui at a central place
Date: Mon, 19 Jan 2009 23:04:48 -0500 [thread overview]
Message-ID: <20090120040448.GA30714@sigill.intra.peff.net> (raw)
In-Reply-To: <200901182137.16562.markus.heidelberg@web.de>
On Sun, Jan 18, 2009 at 09:37:15PM +0100, Markus Heidelberg wrote:
> Not sure, if you it has something to do with the following, but I had
> this in my tree for some days now, waiting for the 2 commits mentioned
> in the log message to graduate to master, which happend just an hour or
> so ago.
I think this is probably an improvement, but I had in mind something a
little more drastic. Right now we keep munging one variable that is our
current idea of "should we do color" based on multiple config values.
Then you end up with (best case) this "finalize color config", which is
a bit ugly, or (worst case) bugs where the value hasn't always been
properly initialized (or finalized).
So I think it makes more sense to record each config value, and then
check a _function_ that does the right thing. I.e., you end up with
something like:
if (use_color(COLOR_DIFF)) /* or COLOR_BRANCH, etc */
...
int use_color(enum color_type t)
{
enum color_preference preference;
preference = color_config[t];
if (preference == COLOR_UNKNOWN)
preference = color_config[COLOR_UI];
if (preference == COLOR_UNKNOWN)
preference = /* some sane default, possibly command-dependent */
if (preference == COLOR_AUTO)
return pager_in_use() || isatty(1);
if (preference == COLOR_ALWAYS)
return 1;
if (preference == COLOR_NEVER)
return 0;
}
which very clearly expresses the policy being used (and you probably
want to memo-ize either that whole thing, or at least the isatty check
to avoid making repeated system calls).
-Peff
next prev parent reply other threads:[~2009-01-20 4:07 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-16 15:06 [PATCH 3/3] Adds a #!bash to the top of bash completions so that editors can recognize, it as a bash script. Also adds a few simple comments above commands that, take arguments. The comments are meant to remind editors of potential, problems that Baz
2009-01-17 1:40 ` Jeff King
2009-01-17 12:37 ` Markus Heidelberg
2009-01-17 15:21 ` Jeff King
2009-01-17 15:32 ` [PATCH 1/2] color: make it easier for non-config to parse color specs Jeff King
2009-01-18 17:10 ` René Scharfe
2009-01-18 17:28 ` Jeff King
2009-01-18 17:36 ` Jeff King
2009-01-18 17:45 ` René Scharfe
2009-01-18 18:06 ` Jeff King
2009-01-17 15:38 ` [PATCH 2/2] expand --pretty=format color options Jeff King
2009-01-18 17:13 ` René Scharfe
2009-01-18 17:37 ` Jeff King
2009-01-18 19:43 ` Jeff King
2009-01-18 19:53 ` Jeff King
2009-01-18 20:37 ` [PATCH 1/2] handle color.ui at a central place Markus Heidelberg
2009-01-18 20:39 ` [PATCH 2/2] move the color variables to color.c Markus Heidelberg
2009-01-20 4:04 ` Jeff King [this message]
2009-01-21 22:35 ` [PATCH 1/2] handle color.ui at a central place Markus Heidelberg
2009-01-22 0:00 ` Jeff King
2009-01-22 0:13 ` Markus Heidelberg
2009-01-23 6:13 ` Junio C Hamano
2009-01-24 11:28 ` Markus Heidelberg
2009-01-24 14:14 ` Johannes Schindelin
2009-01-24 14:23 ` Markus Heidelberg
2009-01-24 18:36 ` Junio C Hamano
2009-01-24 19:17 ` Jeff King
2009-01-24 20:26 ` Junio C Hamano
2009-01-24 20:45 ` Jeff King
2009-01-25 14:15 ` Markus Heidelberg
2009-01-19 23:10 ` [PATCH 2/2] expand --pretty=format color options Junio C Hamano
2009-01-20 4:06 ` Jeff King
2009-01-20 10:27 ` Johannes Schindelin
2009-01-20 10:36 ` Johannes Schindelin
2009-01-20 14:23 ` Jeff King
2009-01-20 14:58 ` Johannes Schindelin
2009-01-20 19:21 ` Jeff King
2009-01-17 15:39 ` Cyellow, was Re: [a way-too-long line] Johannes Schindelin
2009-01-17 15:40 ` Jeff King
2009-01-17 15:46 ` Johannes Schindelin
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090120040448.GA30714@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=markus.heidelberg@web.de \
--cc=rene.scharfe@lsrfire.ath.cx \
/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.
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).