graph: respect the diffopt.file setting

When the caller overrides diffopt.file (which defaults to stdout),
the diff machinery already redirects its output, and the graph display
should also write to that file.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Johannes Schindelin 2016-06-22 17:01:44 +02:00 committed by Junio C Hamano
parent 179795e511
commit c61008fdfb

30
graph.c
View File

@ -17,8 +17,8 @@
static void graph_padding_line(struct git_graph *graph, struct strbuf *sb); static void graph_padding_line(struct git_graph *graph, struct strbuf *sb);
/* /*
* Print a strbuf to stdout. If the graph is non-NULL, all lines but the * Print a strbuf. If the graph is non-NULL, all lines but the first will be
* first will be prefixed with the graph output. * prefixed with the graph output.
* *
* If the strbuf ends with a newline, the output will end after this * If the strbuf ends with a newline, the output will end after this
* newline. A new graph line will not be printed after the final newline. * newline. A new graph line will not be printed after the final newline.
@ -1193,9 +1193,10 @@ void graph_show_commit(struct git_graph *graph)
while (!shown_commit_line && !graph_is_commit_finished(graph)) { while (!shown_commit_line && !graph_is_commit_finished(graph)) {
shown_commit_line = graph_next_line(graph, &msgbuf); shown_commit_line = graph_next_line(graph, &msgbuf);
fwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout); fwrite(msgbuf.buf, sizeof(char), msgbuf.len,
graph->revs->diffopt.file);
if (!shown_commit_line) if (!shown_commit_line)
putchar('\n'); putc('\n', graph->revs->diffopt.file);
strbuf_setlen(&msgbuf, 0); strbuf_setlen(&msgbuf, 0);
} }
@ -1210,7 +1211,7 @@ void graph_show_oneline(struct git_graph *graph)
return; return;
graph_next_line(graph, &msgbuf); graph_next_line(graph, &msgbuf);
fwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout); fwrite(msgbuf.buf, sizeof(char), msgbuf.len, graph->revs->diffopt.file);
strbuf_release(&msgbuf); strbuf_release(&msgbuf);
} }
@ -1222,7 +1223,7 @@ void graph_show_padding(struct git_graph *graph)
return; return;
graph_padding_line(graph, &msgbuf); graph_padding_line(graph, &msgbuf);
fwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout); fwrite(msgbuf.buf, sizeof(char), msgbuf.len, graph->revs->diffopt.file);
strbuf_release(&msgbuf); strbuf_release(&msgbuf);
} }
@ -1239,12 +1240,13 @@ int graph_show_remainder(struct git_graph *graph)
for (;;) { for (;;) {
graph_next_line(graph, &msgbuf); graph_next_line(graph, &msgbuf);
fwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout); fwrite(msgbuf.buf, sizeof(char), msgbuf.len,
graph->revs->diffopt.file);
strbuf_setlen(&msgbuf, 0); strbuf_setlen(&msgbuf, 0);
shown = 1; shown = 1;
if (!graph_is_commit_finished(graph)) if (!graph_is_commit_finished(graph))
putchar('\n'); putc('\n', graph->revs->diffopt.file);
else else
break; break;
} }
@ -1259,7 +1261,8 @@ static void graph_show_strbuf(struct git_graph *graph, struct strbuf const *sb)
char *p; char *p;
if (!graph) { if (!graph) {
fwrite(sb->buf, sizeof(char), sb->len, stdout); fwrite(sb->buf, sizeof(char), sb->len,
graph->revs->diffopt.file);
return; return;
} }
@ -1277,7 +1280,7 @@ static void graph_show_strbuf(struct git_graph *graph, struct strbuf const *sb)
} else { } else {
len = (sb->buf + sb->len) - p; len = (sb->buf + sb->len) - p;
} }
fwrite(p, sizeof(char), len, stdout); fwrite(p, sizeof(char), len, graph->revs->diffopt.file);
if (next_p && *next_p != '\0') if (next_p && *next_p != '\0')
graph_show_oneline(graph); graph_show_oneline(graph);
p = next_p; p = next_p;
@ -1297,7 +1300,8 @@ void graph_show_commit_msg(struct git_graph *graph,
* CMIT_FMT_USERFORMAT are already missing a terminating * CMIT_FMT_USERFORMAT are already missing a terminating
* newline. All of the other formats should have it. * newline. All of the other formats should have it.
*/ */
fwrite(sb->buf, sizeof(char), sb->len, stdout); fwrite(sb->buf, sizeof(char), sb->len,
graph->revs->diffopt.file);
return; return;
} }
@ -1318,7 +1322,7 @@ void graph_show_commit_msg(struct git_graph *graph,
* new line. * new line.
*/ */
if (!newline_terminated) if (!newline_terminated)
putchar('\n'); putc('\n', graph->revs->diffopt.file);
graph_show_remainder(graph); graph_show_remainder(graph);
@ -1326,6 +1330,6 @@ void graph_show_commit_msg(struct git_graph *graph,
* If sb ends with a newline, our output should too. * If sb ends with a newline, our output should too.
*/ */
if (newline_terminated) if (newline_terminated)
putchar('\n'); putc('\n', graph->revs->diffopt.file);
} }
} }