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
- * first will be prefixed with the graph output.
+ * Print a strbuf. If the graph is non-NULL, all lines but the first will be
+ * prefixed with the graph output.
*
* 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.
static void graph_padding_line(struct git_graph *graph, struct strbuf *sb)
{
int i;
+ int chars_written = 0;
if (graph->state != GRAPH_COMMIT) {
graph_next_line(graph, sb);
*/
for (i = 0; i < graph->num_columns; i++) {
struct column *col = &graph->columns[i];
+
strbuf_write_column(sb, col, '|');
- if (col->commit == graph->commit && graph->num_parents > 2)
- strbuf_addchars(sb, ' ', (graph->num_parents - 2) * 2);
- else
+ chars_written++;
+
+ if (col->commit == graph->commit && graph->num_parents > 2) {
+ int len = (graph->num_parents - 2) * 2;
+ strbuf_addchars(sb, ' ', len);
+ chars_written += len;
+ } else {
strbuf_addch(sb, ' ');
+ chars_written++;
+ }
}
- graph_pad_horizontally(graph, sb, graph->num_columns);
+ graph_pad_horizontally(graph, sb, chars_written);
/*
* Update graph->prev_state since we have output a padding line
while (!shown_commit_line && !graph_is_commit_finished(graph)) {
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)
- putchar('\n');
+ putc('\n', graph->revs->diffopt.file);
strbuf_setlen(&msgbuf, 0);
}
return;
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);
}
return;
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);
}
for (;;) {
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);
shown = 1;
if (!graph_is_commit_finished(graph))
- putchar('\n');
+ putc('\n', graph->revs->diffopt.file);
else
break;
}
char *p;
if (!graph) {
- fwrite(sb->buf, sizeof(char), sb->len, stdout);
+ fwrite(sb->buf, sizeof(char), sb->len,
+ graph->revs->diffopt.file);
return;
}
} else {
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')
graph_show_oneline(graph);
p = next_p;
* CMIT_FMT_USERFORMAT are already missing a terminating
* 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;
}
* new line.
*/
if (!newline_terminated)
- putchar('\n');
+ putc('\n', graph->revs->diffopt.file);
graph_show_remainder(graph);
* If sb ends with a newline, our output should too.
*/
if (newline_terminated)
- putchar('\n');
+ putc('\n', graph->revs->diffopt.file);
}
}