[PATCH 34/40] Windows: Make the pager work.

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Johannes Sixt
Date: Wednesday, February 27, 2008 - 11:54 am

Since we have neither fork() nor exec(), we have to spawn the pager and
feed it with the program's output.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
---
 pager.c |   40 ++++++++++++++++++++++++++++++++++++++--
 1 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/pager.c b/pager.c
index ca002f9..3f7f8c1 100644
--- a/pager.c
+++ b/pager.c
@@ -1,12 +1,13 @@
 #include "cache.h"
 
 /*
- * This is split up from the rest of git so that we might do
- * something different on Windows, for example.
+ * This is split up from the rest of git so that we can do
+ * something different on Windows.
  */
 
 static int spawned_pager;
 
+#ifndef __MINGW32__
 static void run_pager(const char *pager)
 {
 	/*
@@ -22,11 +23,31 @@ static void run_pager(const char *pager)
 	execlp(pager, pager, NULL);
 	execl("/bin/sh", "sh", "-c", pager, NULL);
 }
+#else
+#include "run-command.h"
+
+static const char *pager_argv[] = { "sh", "-c", NULL, NULL };
+static struct child_process pager_process = {
+	.argv = pager_argv,
+	.in = -1
+};
+static void wait_for_pager(void)
+{
+	fflush(stdout);
+	fflush(stderr);
+	/* signal EOF to pager */
+	close(1);
+	close(2);
+	finish_command(&pager_process);
+}
+#endif
 
 void setup_pager(void)
 {
+#ifndef __MINGW32__
 	pid_t pid;
 	int fd[2];
+#endif
 	const char *pager = getenv("GIT_PAGER");
 
 	if (!isatty(1))
@@ -45,6 +66,7 @@ void setup_pager(void)
 
 	spawned_pager = 1; /* means we are emitting to terminal */
 
+#ifndef __MINGW32__
 	if (pipe(fd) < 0)
 		return;
 	pid = fork();
@@ -72,6 +94,20 @@ 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 (start_command(&pager_process))
+		return;
+
+	/* original process continues, but writes to the pipe */
+	dup2(pager_process.in, 1);
+	dup2(pager_process.in, 2);
+	close(pager_process.in);
+
+	/* this makes sure that the parent terminates after the pager */
+	atexit(wait_for_pager);
+#endif
 }
 
 int pager_in_use(void)
-- 
1.5.4.1.126.ge5a7d

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 00/40] MinGW port, Johannes Sixt, (Wed Feb 27, 11:54 am)
[PATCH 02/40] Compile some programs only conditionally., Johannes Sixt, (Wed Feb 27, 11:54 am)
[PATCH 03/40] Add target architecture MinGW., Johannes Sixt, (Wed Feb 27, 11:54 am)
[PATCH 09/40] Windows: Work around misbehaved rename()., Johannes Sixt, (Wed Feb 27, 11:54 am)
[PATCH 10/40] Windows: Treat Windows style path names., Johannes Sixt, (Wed Feb 27, 11:54 am)
[PATCH 12/40] Windows: Implement gettimeofday()., Johannes Sixt, (Wed Feb 27, 11:54 am)
[PATCH 13/40] Windows: Fix PRIuMAX definition., Johannes Sixt, (Wed Feb 27, 11:54 am)
[PATCH 18/40] Windows: Implement start_command()., Johannes Sixt, (Wed Feb 27, 11:54 am)
[PATCH 20/40] Windows: A rudimentary poll() emulation., Johannes Sixt, (Wed Feb 27, 11:54 am)
[PATCH 27/40] Windows: Implement a custom spawnve()., Johannes Sixt, (Wed Feb 27, 11:54 am)
[PATCH 30/40] Turn builtin_exec_path into a function., Johannes Sixt, (Wed Feb 27, 11:54 am)
[PATCH 34/40] Windows: Make the pager work., Johannes Sixt, (Wed Feb 27, 11:54 am)
[PATCH 37/40] Windows: Make 'git help -a' work., Johannes Sixt, (Wed Feb 27, 11:55 am)
Re: [PATCH 00/40] MinGW port, Marius Storm-Olsen, (Wed Feb 27, 3:01 pm)
Re: [PATCH 00/40] MinGW port, Martin Langhoff, (Wed Feb 27, 4:34 pm)
Re: [PATCH 01/40] Add compat/regex.[ch] and compat/fnmatch ..., Johannes Schindelin, (Wed Feb 27, 4:43 pm)
Re: [PATCH 00/40] MinGW port, Johannes Schindelin, (Wed Feb 27, 4:58 pm)
Re: [PATCH 00/40] MinGW port, Nguyen Thai Ngoc Duy, (Wed Feb 27, 8:38 pm)
Re: [PATCH 37/40] Windows: Make 'git help -a' work., Paolo Bonzini, (Thu Feb 28, 2:52 am)
Re: [PATCH 02/40] Compile some programs only conditionally., Johannes Schindelin, (Thu Feb 28, 4:57 am)
Re: [PATCH 03/40] Add target architecture MinGW., Johannes Schindelin, (Thu Feb 28, 5:05 am)
Re: [PATCH 08/40] Windows: always chmod(, 0666) before unl ..., Johannes Schindelin, (Thu Feb 28, 5:09 am)
Re: [PATCH 10/40] Windows: Treat Windows style path names., Johannes Schindelin, (Thu Feb 28, 5:18 am)
Re: [PATCH 13/40] Windows: Fix PRIuMAX definition., Johannes Schindelin, (Thu Feb 28, 5:21 am)
Re: [PATCH 03/40] Add target architecture MinGW., Paolo Bonzini, (Thu Feb 28, 5:57 am)
Re: [PATCH 03/40] Add target architecture MinGW., Johannes Schindelin, (Thu Feb 28, 7:56 am)
Re: [PATCH 19/40] Windows: Change the name of hook scripts ..., Johannes Schindelin, (Thu Feb 28, 8:20 am)
Re: [PATCH 21/40] Windows: Disambiguate DOS style paths fr ..., Johannes Schindelin, (Thu Feb 28, 8:22 am)
Re: [PATCH 22/40] Windows: Implement asynchronous function ..., Johannes Schindelin, (Thu Feb 28, 8:28 am)
Re: [PATCH 23/40] Windows: Local clone must use the drive ..., Johannes Schindelin, (Thu Feb 28, 8:31 am)
Re: [PATCH 27/40] Windows: Implement a custom spawnve()., Johannes Schindelin, (Thu Feb 28, 8:36 am)
Re: [PATCH 33/40] When installing, be prepared that templa ..., Johannes Schindelin, (Thu Feb 28, 8:45 am)
Re: [PATCH 40/40] compat/pread.c: Add foward decl to fix w ..., Johannes Schindelin, (Thu Feb 28, 8:51 am)
Re: [PATCH 03/40] Add target architecture MinGW., Johannes Sixt, (Thu Feb 28, 1:40 pm)
Re: [PATCH 13/40] Windows: Fix PRIuMAX definition., Johannes Sixt, (Thu Feb 28, 1:45 pm)
Re: [PATCH 27/40] Windows: Implement a custom spawnve()., Johannes Sixt, (Thu Feb 28, 2:04 pm)
Re: [PATCH 02/40] Compile some programs only conditionally., Johannes Schindelin, (Thu Feb 28, 5:47 pm)
Re: [PATCH 03/40] Add target architecture MinGW., Johannes Schindelin, (Thu Feb 28, 6:07 pm)
Re: [PATCH 04/40] Windows: Use the Windows style PATH sepa ..., Johannes Schindelin, (Thu Feb 28, 6:09 pm)
Re: [PATCH 19/40] Windows: Change the name of hook scripts ..., Johannes Schindelin, (Thu Feb 28, 6:11 pm)
Re: [PATCH 22/40] Windows: Implement asynchronous function ..., Johannes Schindelin, (Thu Feb 28, 6:17 pm)
Re: [PATCH 27/40] Windows: Implement a custom spawnve()., Johannes Schindelin, (Thu Feb 28, 6:18 pm)
Re: [PATCH 33/40] When installing, be prepared that templa ..., Johannes Schindelin, (Thu Feb 28, 6:21 pm)
Re: [PATCH 22/40] Windows: Implement asynchronous function ..., Johannes Schindelin, (Thu Feb 28, 6:27 pm)
Re: [PATCH 22/40] Windows: Implement asynchronous function ..., Johannes Schindelin, (Thu Feb 28, 6:54 pm)
Re: [PATCH 22/40] Windows: Implement asynchronous function ..., Johannes Schindelin, (Fri Feb 29, 3:26 am)
Re: [PATCH 04/40] Windows: Use the Windows style PATH sepa ..., Johannes Schindelin, (Fri Feb 29, 5:19 am)
Re: [PATCH 04/40] Windows: Use the Windows style PATH sepa ..., Johannes Schindelin, (Fri Feb 29, 5:59 am)
Re: [PATCH 03/40] Add target architecture MinGW., Johannes Sixt, (Fri Feb 29, 2:03 pm)
Re: [PATCH 02/40] Compile some programs only conditionally., Johannes Schindelin, (Fri Feb 29, 2:53 pm)
Re: [PATCH 03/40] Add target architecture MinGW., Johannes Schindelin, (Fri Feb 29, 2:54 pm)
Re: [PATCH 20/40] Windows: A rudimentary poll() emulation., Robin Rosenberg, (Sat Mar 1, 8:48 am)
Re: [PATCH 00/40] MinGW port, Johannes Sixt, (Sun Mar 2, 2:20 pm)
Re: [PATCH 00/40] MinGW port, Johannes Schindelin, (Sun Mar 2, 3:07 pm)
Re: [PATCH 00/40] MinGW port, Johannes Sixt, (Mon Mar 3, 11:34 am)
Re: [PATCH 03/40] Add target architecture MinGW., Johannes Sixt, (Wed Mar 5, 2:21 pm)
Re: [PATCH 03/40] Add target architecture MinGW., Johannes Schindelin, (Wed Mar 5, 3:18 pm)
Re: [PATCH 03/40] Add target architecture MinGW., Junio C Hamano, (Wed Mar 5, 3:22 pm)
Re: [PATCH 03/40] Add target architecture MinGW., Johannes Schindelin, (Wed Mar 5, 3:28 pm)
Re: [PATCH 03/40] Add target architecture MinGW., Junio C Hamano, (Wed Mar 5, 3:51 pm)
Re: [PATCH 03/40] Add target architecture MinGW., Johannes Schindelin, (Wed Mar 5, 5:11 pm)
[PATCH 1/2] Add strbuf_initf(), Johannes Schindelin, (Wed Mar 5, 6:14 pm)
[PATCH 2/2] format-patch: add --reviewed-by=&lt;ident&gt;, Johannes Schindelin, (Wed Mar 5, 6:15 pm)
Re: [PATCH 1/2] Add strbuf_initf(), Mike Hommey, (Wed Mar 5, 11:33 pm)
Re: [PATCH 1/2] Add strbuf_initf(), Reece Dunn, (Thu Mar 6, 2:03 am)
Re: [PATCH 2/2] format-patch: add --reviewed-by=&lt;ident&gt;, Johannes Schindelin, (Thu Mar 6, 3:40 am)
Re: [PATCH 1/2] Add strbuf_initf(), Johannes Schindelin, (Thu Mar 6, 3:53 am)
Re: [PATCH 1/2] Add strbuf_initf(), Johannes Schindelin, (Thu Mar 6, 3:55 am)
Re: [PATCH 1/2] Add strbuf_initf(), Reece Dunn, (Thu Mar 6, 4:53 am)
Re: [PATCH 1/2] Add strbuf_initf(), Jeff King, (Thu Mar 6, 5:09 am)
Re: [PATCH 1/2] Add strbuf_initf(), Johannes Schindelin, (Thu Mar 6, 5:52 am)
[PATCH 1/2 v2] Add strbuf_vaddf(), use it in strbuf_addf() ..., Johannes Schindelin, (Thu Mar 6, 9:29 am)
Re: [PATCH 1/2 v2] Add strbuf_vaddf(), use it in strbuf_ad ..., Johannes Schindelin, (Thu Mar 6, 9:59 am)
Re: [PATCH 1/2] Add strbuf_initf(), Kristian , (Thu Mar 6, 11:18 am)
Re: [PATCH 1/2] Add strbuf_initf(), Johannes Schindelin, (Thu Mar 6, 11:26 am)
Re: [PATCH 1/2] Add strbuf_initf(), Kristian , (Thu Mar 6, 11:35 am)
Re: [PATCH 1/2] Add strbuf_initf(), Mike Hommey, (Thu Mar 6, 12:10 pm)
Re: [PATCH 03/40] Add target architecture MinGW., Johannes Sixt, (Thu Mar 6, 1:38 pm)
Re: [PATCH 03/40] Add target architecture MinGW., Johannes Sixt, (Tue Mar 11, 2:30 pm)
Re: [PATCH 03/40] Add target architecture MinGW., Johannes Schindelin, (Tue Mar 11, 4:28 pm)
Re: [PATCH 03/40] Add target architecture MinGW., Johannes Sixt, (Wed Mar 12, 3:59 pm)
Re: [PATCH 03/40] Add target architecture MinGW., Johannes Schindelin, (Wed Mar 12, 4:06 pm)