[PATCH 36/40] Avoid the "dup dance" in wt_status_print_verbose() when possible.
- From
Johannes Sixt <johannes.sixt@telecom.at>
- Date
- Feb 27, 2008, 18:54 UTC
- Message-ID
- <1204138503-6126-37-git-send-email-johannes.sixt@telecom.at>
- In-Reply-To
- <1204138503-6126-1-git-send-email-johannes.sixt@telecom.at>
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 <johannes.sixt@telecom.at> --- wt-status.c | 12 +++++++----- 1 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/wt-status.c b/wt-status.c index 32d780a..e4999ea 100644 --- a/wt-status.c +++ b/wt-status.c @@ -312,15 +312,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); @@ -330,7 +332,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); }
-- 1.5.4.1.126.ge5a7d