git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Write diff output to a file in struct diff_options

From
Kristian Høgsberg <krh@redhat.com>
Date
Mar 10, 2008, 17:58 UTC
Message-ID
<1205171906.31046.27.camel@gaara.boston.redhat.com>
In-Reply-To
<alpine.LNX.1.00.0803092235150.19665@iabervon.org>
On Sun, 2008-03-09 at 22:43 -0400, Daniel Barkalow wrote:
Show 7 quoted lines
> Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
> ---
> I remember there being some expectation that this would be difficult, but 
> it was a pretty straightforward conversion, so I'm wondering if I've 
> missed something. In any case, this is missing tests and documentation for 
> --output=, but I really want it to use directly for rebase-interactive, 
> and I only did the command line option so I could do informal testing.

I ended up just dup()-ing files around in wt-status.c, but it wasn't that converting looked difficult, just that I was trying to finish the builtin-commit work and didn't want to undertake a new rewrite :) With your patch, we can now avoid the dup-dance.

cheers, Kristian

diff --git a/wt-status.c b/wt-status.c
index 32d780a..181821b 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -314,25 +314,13 @@ static void wt_status_print_verbose(struct wt_status *s)
 	struct rev_info rev;
 	int saved_stdout;
 
-	fflush(s->fp);
-
-	/* Sigh, the entire diff machinery is hardcoded to output to
-	 * stdout.  Do the dup-dance...*/
-	saved_stdout = dup(STDOUT_FILENO);
-	if (saved_stdout < 0 ||dup2(fileno(s->fp), STDOUT_FILENO) < 0)
-		die("couldn't redirect stdout\n");
-
 	init_revisions(&rev, NULL);
 	setup_revisions(0, NULL, &rev, s->reference);
 	rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
 	rev.diffopt.detect_rename = 1;
+	rev.diffopt.file = s->fp;
+	rev.diffopt.close_file = 0;
 	run_diff_index(&rev, 1);
-
-	fflush(stdout);
-
-	if (dup2(saved_stdout, STDOUT_FILENO) < 0)
-		die("couldn't restore stdout\n");
-	close(saved_stdout);
 }
 
 void wt_status_print(struct wt_status *s)
Previous: Johannes Schindelin
Message 6 of 6 in “Write diff output to a file in struct diff_options”
  1. Write diff output to a file in struct diff_optionsDaniel Barkalow, Mar 10, 2008
  2. Junio C HamanoMar 10, 2008
  3. Johannes SchindelinMar 10, 2008
  4. Jakub NarebskiMar 10, 2008
  5. Johannes SchindelinMar 10, 2008
  6. Kristian HøgsbergMar 10, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.