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>

Johannes Schindelin committed Jun 22, 2016 at 17:01 UTC c61008fdfb59aff00ec546be6bc6cf3bd8869165
1 file changed +17 -13
graph.c
+17 -13
@@ -17,8 +17,8 @@
17 static void graph_padding_line(struct git_graph *graph, struct strbuf *sb);
18
19 /*
20 - * Print a strbuf to stdout. If the graph is non-NULL, all lines but the
21 - * first will be prefixed with the graph output.
20 + * Print a strbuf. If the graph is non-NULL, all lines but the first will be
21 + * prefixed with the graph output.
22 *
23 * If the strbuf ends with a newline, the output will end after this
24 * 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)
1193
1194 while (!shown_commit_line && !graph_is_commit_finished(graph)) {
1195 shown_commit_line = graph_next_line(graph, &msgbuf);
1196 - fwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout);
1196 + fwrite(msgbuf.buf, sizeof(char), msgbuf.len,
1197 + graph->revs->diffopt.file);
1198 if (!shown_commit_line)
1198 - putchar('\n');
1199 + putc('\n', graph->revs->diffopt.file);
1200 strbuf_setlen(&msgbuf, 0);
1201 }
1202
@@ -1210,7 +1211,7 @@ void graph_show_oneline(struct git_graph *graph)
1211 return;
1212
1213 graph_next_line(graph, &msgbuf);
1213 - fwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout);
1214 + fwrite(msgbuf.buf, sizeof(char), msgbuf.len, graph->revs->diffopt.file);
1215 strbuf_release(&msgbuf);
1216 }
1217
@@ -1222,7 +1223,7 @@ void graph_show_padding(struct git_graph *graph)
1223 return;
1224
1225 graph_padding_line(graph, &msgbuf);
1225 - fwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout);
1226 + fwrite(msgbuf.buf, sizeof(char), msgbuf.len, graph->revs->diffopt.file);
1227 strbuf_release(&msgbuf);
1228 }
1229
@@ -1239,12 +1240,13 @@ int graph_show_remainder(struct git_graph *graph)
1240
1241 for (;;) {
1242 graph_next_line(graph, &msgbuf);
1242 - fwrite(msgbuf.buf, sizeof(char), msgbuf.len, stdout);
1243 + fwrite(msgbuf.buf, sizeof(char), msgbuf.len,
1244 + graph->revs->diffopt.file);
1245 strbuf_setlen(&msgbuf, 0);
1246 shown = 1;
1247
1248 if (!graph_is_commit_finished(graph))
1247 - putchar('\n');
1249 + putc('\n', graph->revs->diffopt.file);
1250 else
1251 break;
1252 }
@@ -1259,7 +1261,8 @@ static void graph_show_strbuf(struct git_graph *graph, struct strbuf const *sb)
1261 char *p;
1262
1263 if (!graph) {
1262 - fwrite(sb->buf, sizeof(char), sb->len, stdout);
1264 + fwrite(sb->buf, sizeof(char), sb->len,
1265 + graph->revs->diffopt.file);
1266 return;
1267 }
1268
@@ -1277,7 +1280,7 @@ static void graph_show_strbuf(struct git_graph *graph, struct strbuf const *sb)
1280 } else {
1281 len = (sb->buf + sb->len) - p;
1282 }
1280 - fwrite(p, sizeof(char), len, stdout);
1283 + fwrite(p, sizeof(char), len, graph->revs->diffopt.file);
1284 if (next_p && *next_p != '\0')
1285 graph_show_oneline(graph);
1286 p = next_p;
@@ -1297,7 +1300,8 @@ void graph_show_commit_msg(struct git_graph *graph,
1300 * CMIT_FMT_USERFORMAT are already missing a terminating
1301 * newline. All of the other formats should have it.
1302 */
1300 - fwrite(sb->buf, sizeof(char), sb->len, stdout);
1303 + fwrite(sb->buf, sizeof(char), sb->len,
1304 + graph->revs->diffopt.file);
1305 return;
1306 }
1307
@@ -1318,7 +1322,7 @@ void graph_show_commit_msg(struct git_graph *graph,
1322 * new line.
1323 */
1324 if (!newline_terminated)
1321 - putchar('\n');
1325 + putc('\n', graph->revs->diffopt.file);
1326
1327 graph_show_remainder(graph);
1328
@@ -1326,6 +1330,6 @@ void graph_show_commit_msg(struct git_graph *graph,
1330 * If sb ends with a newline, our output should too.
1331 */
1332 if (newline_terminated)
1329 - putchar('\n');
1333 + putc('\n', graph->revs->diffopt.file);
1334 }
1335 }