swh:1:snp:6df5a50b8107b6bbe1e51d0239d816a7503c536a
Raw File
Tip revision: 42b5c78845feb44f1d36eecad4c72336d5c2a9c5 authored by Junio C Hamano on 15 April 2006, 06:21:34 UTC
GIT v1.3.0-rc4
Tip revision: 42b5c78
pager.c
#include "cache.h"

/*
 * This is split up from the rest of git so that we might do
 * something different on Windows, for example.
 */

static void run_pager(void)
{
	const char *prog = getenv("PAGER");
	if (!prog)
		prog = "less";
	setenv("LESS", "-S", 0);
	execlp(prog, prog, NULL);
}

void setup_pager(void)
{
	pid_t pid;
	int fd[2];

	if (!isatty(1))
		return;
	if (pipe(fd) < 0)
		return;
	pid = fork();
	if (pid < 0) {
		close(fd[0]);
		close(fd[1]);
		return;
	}

	/* return in the child */
	if (!pid) {
		dup2(fd[1], 1);
		close(fd[0]);
		close(fd[1]);
		return;
	}

	/* The original process turns into the PAGER */
	dup2(fd[0], 0);
	close(fd[0]);
	close(fd[1]);

	run_pager();
	exit(255);
}
back to top