From: Junio C Hamano Date: Tue, 11 Oct 2016 21:19:03 +0000 (-0700) Subject: Merge branch 'jk/graph-padding-fix' into maint X-Git-Tag: v2.10.2~35 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/18fd96f1d706357704c8d51f12b9412cd424ac49?hp=-c Merge branch 'jk/graph-padding-fix' into maint The "graph" API used in "git log --graph" miscounted the number of output columns consumed so far when drawing a padding line, which has been fixed; this did not affect any existing code as nobody tried to write anything after the padding on such a line, though. * jk/graph-padding-fix: graph: fix extra spaces in graph_padding_line --- 18fd96f1d706357704c8d51f12b9412cd424ac49 diff --combined graph.c index dd1720148d,5ad62b8a83..4200f747e7 --- a/graph.c +++ b/graph.c @@@ -17,8 -17,8 +17,8 @@@ 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. @@@ -669,13 -669,6 +669,13 @@@ static void graph_output_padding_line(s graph_pad_horizontally(graph, sb, graph->num_new_columns * 2); } + +int graph_width(struct git_graph *graph) +{ + return graph->width; +} + + static void graph_output_skip_line(struct git_graph *graph, struct strbuf *sb) { /* @@@ -1145,6 -1138,7 +1145,7 @@@ int graph_next_line(struct git_graph *g 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); @@@ -1160,14 -1154,21 +1161,21 @@@ */ 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 @@@ -1200,10 -1201,9 +1208,10 @@@ void graph_show_commit(struct git_grap 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); } @@@ -1218,7 -1218,7 +1226,7 @@@ void graph_show_oneline(struct git_grap 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); } @@@ -1230,7 -1230,7 +1238,7 @@@ void graph_show_padding(struct git_grap 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); } @@@ -1247,13 -1247,12 +1255,13 @@@ int graph_show_remainder(struct git_gra 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; } @@@ -1268,8 -1267,7 +1276,8 @@@ static void graph_show_strbuf(struct gi char *p; if (!graph) { - fwrite(sb->buf, sizeof(char), sb->len, stdout); + fwrite(sb->buf, sizeof(char), sb->len, + graph->revs->diffopt.file); return; } @@@ -1287,7 -1285,7 +1295,7 @@@ } 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; @@@ -1307,8 -1305,7 +1315,8 @@@ void graph_show_commit_msg(struct git_g * 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; } @@@ -1329,7 -1326,7 +1337,7 @@@ * new line. */ if (!newline_terminated) - putchar('\n'); + putc('\n', graph->revs->diffopt.file); graph_show_remainder(graph); @@@ -1337,6 -1334,6 +1345,6 @@@ * If sb ends with a newline, our output should too. */ if (newline_terminated) - putchar('\n'); + putc('\n', graph->revs->diffopt.file); } }