pager: do not fork a pager if PAGER is set to empty.
This skips an extra pipe, and helps debugging tremendously. [jc: PAGER=cat is a questionable hack and should be done as a separate patch. ] Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
Johannes Schindelin committed
Apr 16, 2006 at 04:44 UTC
402461aab17292b78bd36a17bff18e48d544cc9a
1 file changed
+10
-7
pager.c
+10
-7
@@ -5,22 +5,24 @@
5
* something different on Windows, for example.
6
*/
7
8
-static void run_pager(void)
8
+static void run_pager(const char *pager)
9
{
10
- const char *prog = getenv("PAGER");
11
- if (!prog)
12
- prog = "less";
13
- setenv("LESS", "-S", 0);
14
- execlp(prog, prog, NULL);
10
+ execlp(pager, pager, NULL);
11
}
12
13
void setup_pager(void)
14
{
15
pid_t pid;
16
int fd[2];
17
+ const char *pager = getenv("PAGER");
18
19
if (!isatty(1))
20
return;
21
+ if (!pager)
22
+ pager = "less";
23
+ else if (!*pager)
24
+ return;
25
+
26
if (pipe(fd) < 0)
27
return;
28
pid = fork();
@@ -43,6 +45,7 @@ void setup_pager(void)
45
close(fd[0]);
46
close(fd[1]);
47
46
- run_pager();
48
+ setenv("LESS", "-S", 0);
49
+ run_pager(pager);
50
exit(255);
51
}