Skip to content

Commit 18fd96f

Browse files
committed
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
2 parents 1f253d8 + 1647793 commit 18fd96f

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
@@ -1145,6 +1145,7 @@ int graph_next_line(struct git_graph *graph, struct strbuf *sb)
11451145
static void graph_padding_line(struct git_graph *graph, struct strbuf *sb)
11461146
{
11471147
int i;
1148+
int chars_written = 0;
11481149

11491150
if (graph->state != GRAPH_COMMIT) {
11501151
graph_next_line(graph, sb);
@@ -1160,14 +1161,21 @@ static void graph_padding_line(struct git_graph *graph, struct strbuf *sb)
11601161
*/
11611162
for (i = 0; i < graph->num_columns; i++) {
11621163
struct column *col = &graph->columns[i];
1164+
11631165
strbuf_write_column(sb, col, '|');
1164-
if (col->commit == graph->commit && graph->num_parents > 2)
1165-
strbuf_addchars(sb, ' ', (graph->num_parents - 2) * 2);
1166-
else
1166+
chars_written++;
1167+
1168+
if (col->commit == graph->commit && graph->num_parents > 2) {
1169+
int len = (graph->num_parents - 2) * 2;
1170+
strbuf_addchars(sb, ' ', len);
1171+
chars_written += len;
1172+
} else {
11671173
strbuf_addch(sb, ' ');
1174+
chars_written++;
1175+
}
11681176
}
11691177

1170-
graph_pad_horizontally(graph, sb, graph->num_columns);
1178+
graph_pad_horizontally(graph, sb, chars_written);
11711179

11721180
/*
11731181
* Update graph->prev_state since we have output a padding line

0 commit comments

Comments
 (0)