1#include"cache.h" 2 3/* 4 * This is split up from the rest of git so that we might do 5 * something different on Windows, for example. 6 */ 7 8static voidrun_pager(const char*pager) 9{ 10/* 11 * Work around bug in "less" by not starting it until we 12 * have real input 13 */ 14 fd_set in; 15 16FD_ZERO(&in); 17FD_SET(0, &in); 18select(1, &in, NULL, &in, NULL); 19 20execlp(pager, pager, NULL); 21execl("/bin/sh","sh","-c", pager, NULL); 22} 23 24voidsetup_pager(void) 25{ 26 pid_t pid; 27int fd[2]; 28const char*pager =getenv("GIT_PAGER"); 29 30if(!isatty(1)) 31return; 32if(!pager) { 33if(!pager_program) 34git_config(git_default_config); 35 pager = pager_program; 36} 37if(!pager) 38 pager =getenv("PAGER"); 39if(!pager) 40 pager ="less"; 41else if(!*pager || !strcmp(pager,"cat")) 42return; 43 44 pager_in_use =1;/* means we are emitting to terminal */ 45 46if(pipe(fd) <0) 47return; 48 pid =fork(); 49if(pid <0) { 50close(fd[0]); 51close(fd[1]); 52return; 53} 54 55/* return in the child */ 56if(!pid) { 57dup2(fd[1],1); 58close(fd[0]); 59close(fd[1]); 60return; 61} 62 63/* The original process turns into the PAGER */ 64dup2(fd[0],0); 65close(fd[0]); 66close(fd[1]); 67 68setenv("LESS","FRSX",0); 69run_pager(pager); 70die("unable to execute pager '%s'", pager); 71exit(255); 72}