pager: remove 'S' from $LESS by default

By default, Git used to set $LESS to -FRSX if $LESS was not set by the user. The FRX flags actually make sense for Git (F and X because sometimes the output Git pipes to less is short, and R because Git pipes colored output). The S flag (chop long lines), on the other hand, is not related to Git and is a matter of user preference. Git should not decide for the user to change LESS's default. More specifically, the S flag harms users who review untrusted code within a pager, since a patch looking like: -old code; +new good code; [... lots of tabs ...] malicious code; would appear identical to: -old code; +new good code; Users who prefer the old behavior can still set the $LESS environment variable to -FRSX explicitly, or set core.pager to 'less -S'. The documentation in config.txt is made a bit longer to keep both an example setting the 'S' flag (needed to recover the old behavior) and an example showing how to unset a flag set by Git. Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Matthieu Moy committed Apr 30, 2014 at 09:35 UTC b3275838d969b7ecb91aae584226fccbeb046aca
4 files changed +13 -8
Documentation/config.txt
+10 -5
@@ -558,14 +558,19 @@ core.pager::
558 configuration, then `$PAGER`, and then the default chosen at
559 compile time (usually 'less').
560 +
561 -When the `LESS` environment variable is unset, Git sets it to `FRSX`
561 +When the `LESS` environment variable is unset, Git sets it to `FRX`
562 (if `LESS` environment variable is set, Git does not change it at
563 all). If you want to selectively override Git's default setting
564 -for `LESS`, you can set `core.pager` to e.g. `less -+S`. This will
564 +for `LESS`, you can set `core.pager` to e.g. `less -S`. This will
565 be passed to the shell by Git, which will translate the final
566 -command to `LESS=FRSX less -+S`. The environment tells the command
567 -to set the `S` option to chop long lines but the command line
568 -resets it to the default to fold long lines.
566 +command to `LESS=FRX less -S`. The environment does not set the
567 +`S` option but the command line does, instructing less to truncate
568 +long lines. Similarly, setting `core.pager` to `less -+F` will
569 +deactivate the `F` option specified by the environment from the
570 +command-line, deactivating the "quit if one screen" behavior of
571 +`less`. One can specifically activate some flags for particular
572 +commands: for example, setting `pager.blame` to `less -S` enables
573 +line truncation only for `git blame`.
574 +
575 Likewise, when the `LV` environment variable is unset, Git sets it
576 to `-c`. You can override this setting by exporting `LV` with
git-sh-setup.sh
+1 -1
@@ -160,7 +160,7 @@ git_pager() {
160 else
161 GIT_PAGER=cat
162 fi
163 - : ${LESS=-FRSX}
163 + : ${LESS=-FRX}
164 : ${LV=-c}
165 export LESS LV
166
pager.c
+1 -1
@@ -85,7 +85,7 @@ void setup_pager(void)
85 int i = 0;
86
87 if (!getenv("LESS"))
88 - env[i++] = "LESS=FRSX";
88 + env[i++] = "LESS=FRX";
89 if (!getenv("LV"))
90 env[i++] = "LV=-c";
91 env[i] = NULL;
perl/Git/SVN/Log.pm
+1 -1
@@ -116,7 +116,7 @@ sub run_pager {
116 return;
117 }
118 open STDIN, '<&', $rfd or fatal "Can't redirect stdin: $!";
119 - $ENV{LESS} ||= 'FRSX';
119 + $ENV{LESS} ||= 'FRX';
120 $ENV{LV} ||= '-c';
121 exec $pager or fatal "Can't run pager: $! ($pager)";
122 }