mirror of
https://github.com/git/git.git
synced 2026-03-13 18:33:25 +01:00
Make the pager work.
This commit is contained in:
18
pager.c
18
pager.c
@@ -1,19 +1,26 @@
|
||||
#include "cache.h"
|
||||
#include "spawn-pipe.h"
|
||||
|
||||
/*
|
||||
* This is split up from the rest of git so that we might do
|
||||
* something different on Windows, for example.
|
||||
*/
|
||||
|
||||
#ifndef __MINGW32__
|
||||
static void run_pager(const char *pager)
|
||||
{
|
||||
execlp(pager, pager, NULL);
|
||||
execl("/bin/sh", "sh", "-c", pager, NULL);
|
||||
}
|
||||
#endif
|
||||
|
||||
void setup_pager(void)
|
||||
{
|
||||
#ifndef __MINGW32__
|
||||
pid_t pid;
|
||||
#else
|
||||
const char *pager_argv[] = { "sh", "-c", NULL, NULL };
|
||||
#endif
|
||||
int fd[2];
|
||||
const char *pager = getenv("GIT_PAGER");
|
||||
|
||||
@@ -30,6 +37,7 @@ void setup_pager(void)
|
||||
|
||||
if (pipe(fd) < 0)
|
||||
return;
|
||||
#ifndef __MINGW32__
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
close(fd[0]);
|
||||
@@ -54,4 +62,14 @@ void setup_pager(void)
|
||||
run_pager(pager);
|
||||
die("unable to execute pager '%s'", pager);
|
||||
exit(255);
|
||||
#else
|
||||
/* spawn the pager */
|
||||
pager_argv[2] = pager;
|
||||
if (spawnvpe_pipe(pager_argv[0], pager_argv, environ, fd, NULL) < 0)
|
||||
return;
|
||||
|
||||
/* original process continues, but writes to the pipe */
|
||||
dup2(fd[1], 1);
|
||||
close(fd[1]);
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user