Skip to content

Commit 1647793

Browse files
peffgitster
authored andcommitted
graph: fix extra spaces in graph_padding_line
The graph_padding_line() function outputs a series of "|" columns, and then pads with spaces to graph->width by calling graph_pad_horizontally(). However, we tell the latter that we wrote graph->num_columns characters, which is not true; we also needed spaces between the columns. Let's keep a count of how many characters we've written, which is what all the other callers of graph_pad_horizontally() do. Without this, any output that is written at the end of a padding line will be bumped out by at least an extra graph->num_columns spaces. Presumably nobody ever noticed the bug because there's no code path that actually writes to the end of a padding line. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0b65a8d commit 1647793

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

graph.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,7 @@ int graph_next_line(struct git_graph *graph, struct strbuf *sb)
11381138
static void graph_padding_line(struct git_graph *graph, struct strbuf *sb)
11391139
{
11401140
int i;
1141+
int chars_written = 0;
11411142

11421143
if (graph->state != GRAPH_COMMIT) {
11431144
graph_next_line(graph, sb);
@@ -1153,14 +1154,21 @@ static void graph_padding_line(struct git_graph *graph, struct strbuf *sb)
11531154
*/
11541155
for (i = 0; i < graph->num_columns; i++) {
11551156
struct column *col = &graph->columns[i];
1157+
11561158
strbuf_write_column(sb, col, '|');
1157-
if (col->commit == graph->commit && graph->num_parents > 2)
1158-
strbuf_addchars(sb, ' ', (graph->num_parents - 2) * 2);
1159-
else
1159+
chars_written++;
1160+
1161+
if (col->commit == graph->commit && graph->num_parents > 2) {
1162+
int len = (graph->num_parents - 2) * 2;
1163+
strbuf_addchars(sb, ' ', len);
1164+
chars_written += len;
1165+
} else {
11601166
strbuf_addch(sb, ' ');
1167+
chars_written++;
1168+
}
11611169
}
11621170

1163-
graph_pad_horizontally(graph, sb, graph->num_columns);
1171+
graph_pad_horizontally(graph, sb, chars_written);
11641172

11651173
/*
11661174
* Update graph->prev_state since we have output a padding line

0 commit comments

Comments
 (0)