Skip to content

Commit c61008f

Browse files
dschogitster
authored andcommitted
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>
1 parent 179795e commit c61008f

1 file changed

Lines changed: 17 additions & 13 deletions

File tree

graph.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
static void graph_padding_line(struct git_graph *graph, struct strbuf *sb);
1818

1919
/*
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.
2222
*
2323
* If the strbuf ends with a newline, the output will end after this
2424
* 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)
11931193

11941194
while (!shown_commit_line && !graph_is_commit_finished(graph)) {
11951195
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);
11971198
if (!shown_commit_line)
1198-
putchar('\n');
1199+
putc('\n', graph->revs->diffopt.file);
11991200
strbuf_setlen(&msgbuf, 0);
12001201
}
12011202

@@ -1210,7 +1211,7 @@ void graph_show_oneline(struct git_graph *graph)
12101211
return;
12111212

12121213
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);
12141215
strbuf_release(&msgbuf);
12151216
}
12161217

@@ -1222,7 +1223,7 @@ void graph_show_padding(struct git_graph *graph)
12221223
return;
12231224

12241225
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);
12261227
strbuf_release(&msgbuf);
12271228
}
12281229

@@ -1239,12 +1240,13 @@ int graph_show_remainder(struct git_graph *graph)
12391240

12401241
for (;;) {
12411242
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);
12431245
strbuf_setlen(&msgbuf, 0);
12441246
shown = 1;
12451247

12461248
if (!graph_is_commit_finished(graph))
1247-
putchar('\n');
1249+
putc('\n', graph->revs->diffopt.file);
12481250
else
12491251
break;
12501252
}
@@ -1259,7 +1261,8 @@ static void graph_show_strbuf(struct git_graph *graph, struct strbuf const *sb)
12591261
char *p;
12601262

12611263
if (!graph) {
1262-
fwrite(sb->buf, sizeof(char), sb->len, stdout);
1264+
fwrite(sb->buf, sizeof(char), sb->len,
1265+
graph->revs->diffopt.file);
12631266
return;
12641267
}
12651268

@@ -1277,7 +1280,7 @@ static void graph_show_strbuf(struct git_graph *graph, struct strbuf const *sb)
12771280
} else {
12781281
len = (sb->buf + sb->len) - p;
12791282
}
1280-
fwrite(p, sizeof(char), len, stdout);
1283+
fwrite(p, sizeof(char), len, graph->revs->diffopt.file);
12811284
if (next_p && *next_p != '\0')
12821285
graph_show_oneline(graph);
12831286
p = next_p;
@@ -1297,7 +1300,8 @@ void graph_show_commit_msg(struct git_graph *graph,
12971300
* CMIT_FMT_USERFORMAT are already missing a terminating
12981301
* newline. All of the other formats should have it.
12991302
*/
1300-
fwrite(sb->buf, sizeof(char), sb->len, stdout);
1303+
fwrite(sb->buf, sizeof(char), sb->len,
1304+
graph->revs->diffopt.file);
13011305
return;
13021306
}
13031307

@@ -1318,14 +1322,14 @@ void graph_show_commit_msg(struct git_graph *graph,
13181322
* new line.
13191323
*/
13201324
if (!newline_terminated)
1321-
putchar('\n');
1325+
putc('\n', graph->revs->diffopt.file);
13221326

13231327
graph_show_remainder(graph);
13241328

13251329
/*
13261330
* If sb ends with a newline, our output should too.
13271331
*/
13281332
if (newline_terminated)
1329-
putchar('\n');
1333+
putc('\n', graph->revs->diffopt.file);
13301334
}
13311335
}

0 commit comments

Comments
 (0)