Make the pager work.

This commit is contained in:
Johannes Sixt
2007-01-18 09:37:38 +01:00
parent 5f38ff014e
commit ec1fcbb0a9

18
pager.c
View File

@@ -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
}