From 3805d587572fd50b2e8bb6af6b1dbccffb6807e5 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Mon, 10 Dec 2007 12:55:35 +0100 Subject: [PATCH] Avoid the "dup dance" in wt_status_print_verbose() when possible. If the status output already goes to stdout, then it is not necessary to redirect stdout for the diff machinery. (This case hangs on Windows for unknown reasons.) Signed-off-by: Johannes Sixt --- wt-status.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/wt-status.c b/wt-status.c index 51c1879691..9a2d3c65b7 100644 --- a/wt-status.c +++ b/wt-status.c @@ -321,15 +321,17 @@ static void wt_status_print_untracked(struct wt_status *s) static void wt_status_print_verbose(struct wt_status *s) { struct rev_info rev; - int saved_stdout; + int saved_stdout = -1; 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"); + if (fileno(s->fp) != STDOUT_FILENO) { + 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); @@ -340,7 +342,7 @@ static void wt_status_print_verbose(struct wt_status *s) fflush(stdout); - if (dup2(saved_stdout, STDOUT_FILENO) < 0) + if (saved_stdout >= 0 && dup2(saved_stdout, STDOUT_FILENO) < 0) die("couldn't restore stdout\n"); close(saved_stdout); }