11#include "cache.h"
22
33/*
4- * This is split up from the rest of git so that we might do
5- * something different on Windows, for example .
4+ * This is split up from the rest of git so that we can do
5+ * something different on Windows.
66 */
77
88static int spawned_pager ;
99
10+ #ifndef __MINGW32__
1011static void run_pager (const char * pager )
1112{
1213 /*
@@ -22,11 +23,31 @@ static void run_pager(const char *pager)
2223 execlp (pager , pager , NULL );
2324 execl ("/bin/sh" , "sh" , "-c" , pager , NULL );
2425}
26+ #else
27+ #include "run-command.h"
28+
29+ static const char * pager_argv [] = { "sh" , "-c" , NULL , NULL };
30+ static struct child_process pager_process = {
31+ .argv = pager_argv ,
32+ .in = -1
33+ };
34+ static void wait_for_pager (void )
35+ {
36+ fflush (stdout );
37+ fflush (stderr );
38+ /* signal EOF to pager */
39+ close (1 );
40+ close (2 );
41+ finish_command (& pager_process );
42+ }
43+ #endif
2544
2645void setup_pager (void )
2746{
47+ #ifndef __MINGW32__
2848 pid_t pid ;
2949 int fd [2 ];
50+ #endif
3051 const char * pager = getenv ("GIT_PAGER" );
3152
3253 if (!isatty (1 ))
@@ -45,6 +66,7 @@ void setup_pager(void)
4566
4667 spawned_pager = 1 ; /* means we are emitting to terminal */
4768
69+ #ifndef __MINGW32__
4870 if (pipe (fd ) < 0 )
4971 return ;
5072 pid = fork ();
@@ -72,6 +94,20 @@ void setup_pager(void)
7294 run_pager (pager );
7395 die ("unable to execute pager '%s'" , pager );
7496 exit (255 );
97+ #else
98+ /* spawn the pager */
99+ pager_argv [2 ] = pager ;
100+ if (start_command (& pager_process ))
101+ return ;
102+
103+ /* original process continues, but writes to the pipe */
104+ dup2 (pager_process .in , 1 );
105+ dup2 (pager_process .in , 2 );
106+ close (pager_process .in );
107+
108+ /* this makes sure that the parent terminates after the pager */
109+ atexit (wait_for_pager );
110+ #endif
75111}
76112
77113int pager_in_use (void )
0 commit comments