pager: set LV=-c alongside LESS=FRSX

On systems with lv configured as the preferred pager (i.e., DEFAULT_PAGER=lv at build time, or PAGER=lv exported in the environment) git commands that use color show control codes instead of color in the pager: $ git diff ^[[1mdiff --git a/.mailfilter b/.mailfilter^[[m ^[[1mindex aa4f0b2..17e113e 100644^[[m ^[[1m--- a/.mailfilter^[[m ^[[1m+++ b/.mailfilter^[[m ^[[36m@@ -1,11 +1,58 @@^[[m "less" avoids this problem because git uses the LESS environment variable to pass the -R option ('output ANSI color escapes in raw form') by default. Use the LV environment variable to pass 'lv' the -c option ('allow ANSI escape sequences for text decoration / color') to fix it for lv, too. Noticed when the default value for color.ui flipped to 'auto' in v1.8.4-rc0~36^2~1 (2013-06-10). Reported-by: Olaf Meeuwissen <olaf.meeuwissen@avasys.jp> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jonathan Nieder committed Jan 6, 2014 at 18:14 UTC e54c1f2d2533c5406abeb8e3e0cf78c68ca9c21e
5 files changed +28 -3
Documentation/config.txt
+4
@@ -567,6 +567,10 @@ be passed to the shell by Git, which will translate the final
567 command to `LESS=FRSX less -+S`. The environment tells the command
568 to set the `S` option to chop long lines but the command line
569 resets it to the default to fold long lines.
570 ++
571 +Likewise, when the `LV` environment variable is unset, Git sets it
572 +to `-c`. You can override this setting by exporting `LV` with
573 +another value or setting `core.pager` to `lv +c`.
574
575 core.whitespace::
576 A comma separated list of common whitespace problems to
git-sh-setup.sh
+2 -1
@@ -162,7 +162,8 @@ git_pager() {
162 GIT_PAGER=cat
163 fi
164 : ${LESS=-FRSX}
165 - export LESS
165 + : ${LV=-c}
166 + export LESS LV
167
168 eval "$GIT_PAGER" '"$@"'
169 }
pager.c
+9 -2
@@ -80,8 +80,15 @@ void setup_pager(void)
80 pager_process.use_shell = 1;
81 pager_process.argv = pager_argv;
82 pager_process.in = -1;
83 - if (!getenv("LESS")) {
84 - static const char *env[] = { "LESS=FRSX", NULL };
83 + if (!getenv("LESS") || !getenv("LV")) {
84 + static const char *env[3];
85 + int i = 0;
86 +
87 + if (!getenv("LESS"))
88 + env[i++] = "LESS=FRSX";
89 + if (!getenv("LV"))
90 + env[i++] = "LV=-c";
91 + env[i] = NULL;
92 pager_process.env = env;
93 }
94 if (start_command(&pager_process))
perl/Git/SVN/Log.pm
+1
@@ -117,6 +117,7 @@ sub run_pager {
117 }
118 open STDIN, '<&', $rfd or fatal "Can't redirect stdin: $!";
119 $ENV{LESS} ||= 'FRSX';
120 + $ENV{LV} ||= '-c';
121 exec $pager or fatal "Can't run pager: $! ($pager)";
122 }
123
t/t7006-pager.sh
+12
@@ -37,6 +37,18 @@ test_expect_failure TTY 'pager runs from subdir' '
37 test_cmp expected actual
38 '
39
40 +test_expect_success TTY 'LESS and LV envvars are set for pagination' '
41 + (
42 + sane_unset LESS LV &&
43 + PAGER="env >pager-env.out" &&
44 + export PAGER &&
45 +
46 + test_terminal git log
47 + ) &&
48 + grep ^LESS= pager-env.out &&
49 + grep ^LV= pager-env.out
50 +'
51 +
52 test_expect_success TTY 'some commands do not use a pager' '
53 rm -f paginated.out &&
54 test_terminal git rev-list HEAD &&