Browse Source

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>
maint
Jonathan Nieder 11 years ago committed by Junio C Hamano
parent
commit
e54c1f2d25
  1. 4
      Documentation/config.txt
  2. 3
      git-sh-setup.sh
  3. 11
      pager.c
  4. 1
      perl/Git/SVN/Log.pm
  5. 12
      t/t7006-pager.sh

4
Documentation/config.txt

@ -567,6 +567,10 @@ be passed to the shell by Git, which will translate the final
command to `LESS=FRSX less -+S`. The environment tells the command command to `LESS=FRSX less -+S`. The environment tells the command
to set the `S` option to chop long lines but the command line to set the `S` option to chop long lines but the command line
resets it to the default to fold long lines. resets it to the default to fold long lines.
+
Likewise, when the `LV` environment variable is unset, Git sets it
to `-c`. You can override this setting by exporting `LV` with
another value or setting `core.pager` to `lv +c`.


core.whitespace:: core.whitespace::
A comma separated list of common whitespace problems to A comma separated list of common whitespace problems to

3
git-sh-setup.sh

@ -162,7 +162,8 @@ git_pager() {
GIT_PAGER=cat GIT_PAGER=cat
fi fi
: ${LESS=-FRSX} : ${LESS=-FRSX}
export LESS : ${LV=-c}
export LESS LV


eval "$GIT_PAGER" '"$@"' eval "$GIT_PAGER" '"$@"'
} }

11
pager.c

@ -80,8 +80,15 @@ void setup_pager(void)
pager_process.use_shell = 1; pager_process.use_shell = 1;
pager_process.argv = pager_argv; pager_process.argv = pager_argv;
pager_process.in = -1; pager_process.in = -1;
if (!getenv("LESS")) { if (!getenv("LESS") || !getenv("LV")) {
static const char *env[] = { "LESS=FRSX", NULL }; static const char *env[3];
int i = 0;

if (!getenv("LESS"))
env[i++] = "LESS=FRSX";
if (!getenv("LV"))
env[i++] = "LV=-c";
env[i] = NULL;
pager_process.env = env; pager_process.env = env;
} }
if (start_command(&pager_process)) if (start_command(&pager_process))

1
perl/Git/SVN/Log.pm

@ -117,6 +117,7 @@ sub run_pager {
} }
open STDIN, '<&', $rfd or fatal "Can't redirect stdin: $!"; open STDIN, '<&', $rfd or fatal "Can't redirect stdin: $!";
$ENV{LESS} ||= 'FRSX'; $ENV{LESS} ||= 'FRSX';
$ENV{LV} ||= '-c';
exec $pager or fatal "Can't run pager: $! ($pager)"; exec $pager or fatal "Can't run pager: $! ($pager)";
} }



12
t/t7006-pager.sh

@ -37,6 +37,18 @@ test_expect_failure TTY 'pager runs from subdir' '
test_cmp expected actual test_cmp expected actual
' '


test_expect_success TTY 'LESS and LV envvars are set for pagination' '
(
sane_unset LESS LV &&
PAGER="env >pager-env.out" &&
export PAGER &&

test_terminal git log
) &&
grep ^LESS= pager-env.out &&
grep ^LV= pager-env.out
'

test_expect_success TTY 'some commands do not use a pager' ' test_expect_success TTY 'some commands do not use a pager' '
rm -f paginated.out && rm -f paginated.out &&
test_terminal git rev-list HEAD && test_terminal git rev-list HEAD &&

Loading…
Cancel
Save