Skip to content

Commit 402461a

Browse files
dschoJunio C Hamano
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2935327 commit 402461a

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

pager.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,24 @@
55
* something different on Windows, for example.
66
*/
77

8-
static void run_pager(void)
8+
static void run_pager(const char *pager)
99
{
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);
1511
}
1612

1713
void setup_pager(void)
1814
{
1915
pid_t pid;
2016
int fd[2];
17+
const char *pager = getenv("PAGER");
2118

2219
if (!isatty(1))
2320
return;
21+
if (!pager)
22+
pager = "less";
23+
else if (!*pager)
24+
return;
25+
2426
if (pipe(fd) < 0)
2527
return;
2628
pid = fork();
@@ -43,6 +45,7 @@ void setup_pager(void)
4345
close(fd[0]);
4446
close(fd[1]);
4547

46-
run_pager();
48+
setenv("LESS", "-S", 0);
49+
run_pager(pager);
4750
exit(255);
4851
}

0 commit comments

Comments
 (0)