git/builtin
Jeff King daa0c3d971 color: delay auto-color decision until point of use
When we read a color value either from a config file or from
the command line, we use git_config_colorbool to convert it
from the tristate always/never/auto into a single yes/no
boolean value.

This has some timing implications with respect to starting
a pager.

If we start (or decide not to start) the pager before
checking the colorbool, everything is fine. Either isatty(1)
will give us the right information, or we will properly
check for pager_in_use().

However, if we decide to start a pager after we have checked
the colorbool, things are not so simple. If stdout is a tty,
then we will have already decided to use color. However, the
user may also have configured color.pager not to use color
with the pager. In this case, we need to actually turn off
color. Unfortunately, the pager code has no idea which color
variables were turned on (and there are many of them
throughout the code, and they may even have been manipulated
after the colorbool selection by something like "--color" on
the command line).

This bug can be seen any time a pager is started after
config and command line options are checked. This has
affected "git diff" since 89d07f7 (diff: don't run pager if
user asked for a diff style exit code, 2007-08-12). It has
also affect the log family since 1fda91b (Fix 'git log'
early pager startup error case, 2010-08-24).

This patch splits the notion of parsing a colorbool and
actually checking the configuration. The "use_color"
variables now have an additional possible value,
GIT_COLOR_AUTO. Users of the variable should use the new
"want_color()" wrapper, which will lazily determine and
cache the auto-color decision.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-08-19 15:51:34 -07:00
..
add.c Merge branch 'ci/commit--interactive-atomic' 2011-05-16 16:47:10 -07:00
annotate.c
apply.c zlib: zlib can only process 4GB at a time 2011-06-10 11:52:15 -07:00
archive.c i18n: git-archive basic messages 2011-03-09 23:52:57 -08:00
bisect--helper.c
blame.c blame: add --line-porcelain output format 2011-05-09 15:27:50 -07:00
branch.c color: delay auto-color decision until point of use 2011-08-19 15:51:34 -07:00
bundle.c i18n: git-bundle basic messages 2011-03-09 23:52:57 -08:00
cat-file.c plug a few coverity-spotted leaks 2011-06-20 14:27:36 -07:00
check-attr.c
check-ref-format.c
checkout-index.c checkout-index: remove obsolete comment 2011-08-17 10:39:47 -07:00
checkout.c Merge branch 'jc/checkout-reflog-fix' into maint 2011-08-16 12:41:12 -07:00
clean.c i18n: git-clean clean.requireForce messages 2011-03-09 23:52:57 -08:00
clone.c Merge branch 'ab/i18n-fixup' into maint 2011-05-31 12:00:27 -07:00
commit-tree.c
commit.c git_config_colorbool: refactor stdout_is_tty handling 2011-08-18 14:48:29 -07:00
config.c color: delay auto-color decision until point of use 2011-08-19 15:51:34 -07:00
count-objects.c add description parameter to OPT__VERBOSE 2010-11-15 09:56:51 -08:00
describe.c Merge branch 'lt/default-abbrev' into maint 2011-04-03 12:32:51 -07:00
diff-files.c Convert struct diff_options to use struct pathspec 2011-02-03 12:28:15 -08:00
diff-index.c
diff-tree.c diffcore-rename: fall back to -C when -C -C busts the rename limit 2011-03-22 14:29:07 -07:00
diff.c plug a few coverity-spotted leaks 2011-06-20 14:27:36 -07:00
fast-export.c Merge branch 'jk/fast-export-quote-path' into maint 2011-08-16 12:41:12 -07:00
fetch-pack.c Merge branch 'jk/haves-from-alternate-odb' 2011-05-29 23:51:22 -07:00
fetch.c fetch: do not leak a refspec 2011-06-08 17:21:08 -07:00
fmt-merge-msg.c Fix sparse warnings 2011-03-22 10:16:54 -07:00
for-each-ref.c
fsck.c Remove unused variables 2011-03-22 11:43:27 -07:00
gc.c builtin/gc.c: add missing newline in message 2011-06-19 14:46:39 -07:00
grep.c git_config_colorbool: refactor stdout_is_tty handling 2011-08-18 14:48:29 -07:00
hash-object.c index_fd(): turn write_object and format_check arguments into one flag 2011-05-09 11:58:19 -07:00
help.c
index-pack.c Merge branch 'jc/zlib-wrap' into maint 2011-08-16 11:23:26 -07:00
init-db.c Merge branch 'ab/i18n-fixup' into maint 2011-05-31 12:00:27 -07:00
log.c Merge branch 'jk/format-patch-am' 2011-05-31 12:19:11 -07:00
ls-files.c pathspec: rename per-item field has_wildcard to use_wildcard 2011-04-05 09:30:36 -07:00
ls-remote.c ls-remote: the --exit-code option reports "no matching refs" 2011-05-18 14:37:46 -07:00
ls-tree.c Ensure git ls-tree exits with a non-zero exit code if read_tree_recursive fails. 2011-07-25 10:50:11 -07:00
mailinfo.c mailinfo: always clean up rfc822 header folding 2011-05-26 14:13:38 -07:00
mailsplit.c
merge-base.c Documentation: update to git-merge-base --octopus 2011-04-15 10:13:52 -07:00
merge-file.c Merge branch 'rs/opt-help-text' 2010-11-24 15:55:19 -08:00
merge-index.c Fix sparse warnings 2011-03-22 10:16:54 -07:00
merge-ours.c
merge-recursive.c Fix sparse warnings 2011-03-22 10:16:54 -07:00
merge-tree.c sparse: Fix an "symbol 'merge_file' not decared" warning 2011-04-11 10:35:25 -07:00
merge.c diff: refactor COLOR_DIFF from a flag into an int 2011-08-18 14:35:53 -07:00
mktag.c read_sha1_file(): get rid of read_sha1_file_repl() madness 2011-05-15 15:23:33 -07:00
mktree.c
mv.c i18n: git-mv "bad" messages 2011-03-09 23:52:56 -08:00
name-rev.c
notes.c notes remove: --stdin reads from the standard input 2011-05-19 10:54:16 -07:00
pack-objects.c zlib: zlib can only process 4GB at a time 2011-06-10 11:52:15 -07:00
pack-redundant.c Fix sparse warnings 2011-03-22 10:16:54 -07:00
pack-refs.c Fix sparse warnings 2011-03-22 10:16:54 -07:00
patch-id.c Fix sparse warnings 2011-03-22 10:16:54 -07:00
prune-packed.c
prune.c add description parameter to OPT__DRY_RUN 2010-11-15 09:57:37 -08:00
push.c Merge branch 'ab/i18n-st' 2011-04-01 17:55:55 -07:00
read-tree.c Teach read-tree the -n|--dry-run option 2011-05-25 15:04:25 -07:00
receive-pack.c receive-pack: eliminate duplicate .have refs 2011-05-19 20:02:31 -07:00
reflog.c
remote-ext.c Remove unused variables 2011-03-22 11:43:27 -07:00
remote-fd.c Fix sparse warnings 2011-03-22 10:16:54 -07:00
remote.c Merge branch 'jk/maint-remote-mirror-safer' 2011-05-31 12:08:52 -07:00
replace.c
rerere.c rerere: libify rerere_clear() and rerere_gc() 2011-05-08 12:55:34 -07:00
reset.c reset [<commit>] paths...: do not mishandle unmerged paths 2011-07-13 21:39:18 -07:00
rev-list.c Merge branch 'jk/format-patch-am' 2011-05-31 12:19:11 -07:00
rev-parse.c show: --ignore-missing 2011-05-19 10:55:54 -07:00
revert.c revert: allow reverting a root commit 2011-05-16 13:01:45 -07:00
rm.c i18n: git-rm basic messages 2011-03-09 23:52:56 -08:00
send-pack.c Merge branch 'jk/git-connection-deadlock-fix' into maint 2011-05-26 09:33:25 -07:00
shortlog.c Merge branch 'jk/format-patch-am' 2011-05-31 12:19:11 -07:00
show-branch.c color: delay auto-color decision until point of use 2011-08-19 15:51:34 -07:00
show-ref.c Describe various forms of "be quiet" using OPT__QUIET 2010-11-15 10:04:56 -08:00
stripspace.c
symbolic-ref.c Describe various forms of "be quiet" using OPT__QUIET 2010-11-15 10:04:56 -08:00
tag.c Merge branch 'jk/tag-list-multiple-patterns' into maint 2011-08-16 12:41:14 -07:00
tar-tree.c
unpack-file.c Fix sparse warnings 2011-03-22 10:16:54 -07:00
unpack-objects.c zlib: zlib can only process 4GB at a time 2011-06-10 11:52:15 -07:00
update-index.c plug a few coverity-spotted leaks 2011-06-20 14:27:36 -07:00
update-ref.c
update-server-info.c add OPT__FORCE 2010-11-15 10:04:43 -08:00
upload-archive.c
var.c Fix sparse warnings 2011-03-22 10:16:54 -07:00
verify-pack.c
verify-tag.c Merge branch 'mg/maint-tag-rfc1991' 2010-12-08 11:24:13 -08:00
write-tree.c