Merge branch 'jn/pager-lv-default-env'
authorJunio C Hamano <gitster@pobox.com>
Mon, 13 Jan 2014 19:33:34 +0000 (11:33 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 13 Jan 2014 19:33:35 +0000 (11:33 -0800)
Just like we give a reasonable default for "less" via the LESS
environment variable, specify a reasonable default for "lv" via the
"LV" environment variable when spawning the pager.

* jn/pager-lv-default-env:
pager: set LV=-c alongside LESS=FRSX

Documentation/config.txt
git-sh-setup.sh
pager.c
perl/Git/SVN/Log.pm
t/t7006-pager.sh
index a4058063cedd61d88990faf739bda955834b1ea7..ed5985319089e287b5ada6353d42b1e81568290c 100644 (file)
@@ -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
 to set the `S` option to chop long lines but the command line
 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::
        A comma separated list of common whitespace problems to
index 190a5394b9265270faadf578685e9a12b4efebfd..fffa3c72d75961159888fd156614aa6679f3638c 100644 (file)
@@ -159,7 +159,8 @@ git_pager() {
                GIT_PAGER=cat
        fi
        : ${LESS=-FRSX}
-       export LESS
+       : ${LV=-c}
+       export LESS LV
 
        eval "$GIT_PAGER" '"$@"'
 }
diff --git a/pager.c b/pager.c
index 345b0bc4b58ef641a653d6244d2ef7558fc84347..0cc75a8eee32a0195a74c6819a04745f341e45e3 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -80,8 +80,15 @@ void setup_pager(void)
        pager_process.use_shell = 1;
        pager_process.argv = pager_argv;
        pager_process.in = -1;
-       if (!getenv("LESS")) {
-               static const char *env[] = { "LESS=FRSX", NULL };
+       if (!getenv("LESS") || !getenv("LV")) {
+               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;
        }
        if (start_command(&pager_process))
index 3f8350a57d64ca3335d279c6563fad54b56eb22a..34f2869ab5995e3f9143af8cc2c46a4717ae8be8 100644 (file)
@@ -117,6 +117,7 @@ sub run_pager {
        }
        open STDIN, '<&', $rfd or fatal "Can't redirect stdin: $!";
        $ENV{LESS} ||= 'FRSX';
+       $ENV{LV} ||= '-c';
        exec $pager or fatal "Can't run pager: $! ($pager)";
 }
 
index ff2590849de960cf6ec751f83904f1792862f626..7fe3367b6b6b8f4373dfdb9ffc956f8e1670801a 100755 (executable)
@@ -37,6 +37,18 @@ test_expect_failure TTY 'pager runs from subdir' '
        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' '
        rm -f paginated.out &&
        test_terminal git rev-list HEAD &&