Skip to content

Commit a1087c9

Browse files
derrickstoleegitster
authored andcommitted
graph: fix lack of color in horizontal lines
In some cases, horizontal lines in rendered graphs can lose their coloring. This is due to a use of graph_line_addch() instead of graph_line_write_column(). Using a ternary operator to pick the character is nice for compact code, but we actually need a column to provide the color. Add a test to t4215-log-skewed-merges.sh to prevent regression. Reported-by: Jeff King <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0d251c3 commit a1087c9

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

graph.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ static void graph_output_post_merge_line(struct git_graph *graph, struct graph_l
10631063
int i, j;
10641064

10651065
struct commit_list *first_parent = first_interesting_parent(graph);
1066-
int seen_parent = 0;
1066+
struct column *parent_col = NULL;
10671067

10681068
/*
10691069
* Output the post-merge row
@@ -1117,12 +1117,17 @@ static void graph_output_post_merge_line(struct git_graph *graph, struct graph_l
11171117
graph_line_addch(line, ' ');
11181118
} else {
11191119
graph_line_write_column(line, col, '|');
1120-
if (graph->merge_layout != 0 || i != graph->commit_index - 1)
1121-
graph_line_addch(line, seen_parent ? '_' : ' ');
1120+
if (graph->merge_layout != 0 || i != graph->commit_index - 1) {
1121+
if (parent_col)
1122+
graph_line_write_column(
1123+
line, parent_col, '_');
1124+
else
1125+
graph_line_addch(line, ' ');
1126+
}
11221127
}
11231128

11241129
if (col_commit == first_parent->item)
1125-
seen_parent = 1;
1130+
parent_col = col;
11261131
}
11271132

11281133
/*

t/t4215-log-skewed-merges.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,4 +282,33 @@ test_expect_success 'log --graph with multiple tips' '
282282
EOF
283283
'
284284

285+
test_expect_success 'log --graph with multiple tips and colors' '
286+
test_config log.graphColors red,green,yellow,blue,magenta,cyan &&
287+
cat >expect.colors <<-\EOF &&
288+
* 6_I
289+
<RED>|<RESET><GREEN>\<RESET>
290+
<RED>|<RESET> <GREEN>|<RESET> * 6_H
291+
<RED>|<RESET> <GREEN>|<RESET> <YELLOW>|<RESET><BLUE>\<RESET>
292+
<RED>|<RESET> <GREEN>|<RESET> <YELLOW>|<RESET> * 6_G
293+
<RED>|<RESET> <GREEN>|<RESET> <YELLOW>|<RESET> <BLUE>|<RESET> * 6_F
294+
<RED>|<RESET> <GREEN>|<RESET><RED>_<RESET><YELLOW>|<RESET><RED>_<RESET><BLUE>|<RESET><RED>/<RESET><GREEN>|<RESET>
295+
<RED>|<RESET><RED>/<RESET><GREEN>|<RESET> <YELLOW>|<RESET> <BLUE>|<RESET><GREEN>/<RESET>
296+
<RED>|<RESET> <GREEN>|<RESET> <YELLOW>|<RESET><GREEN>/<RESET><BLUE>|<RESET>
297+
<RED>|<RESET> <GREEN>|<RESET><GREEN>/<RESET><YELLOW>|<RESET> <BLUE>|<RESET>
298+
<RED>|<RESET> <GREEN>|<RESET> * <BLUE>|<RESET> 6_E
299+
<RED>|<RESET> * <CYAN>|<RESET> <BLUE>|<RESET> 6_D
300+
<RED>|<RESET> <BLUE>|<RESET> <CYAN>|<RESET><BLUE>/<RESET>
301+
<RED>|<RESET> <BLUE>|<RESET><BLUE>/<RESET><CYAN>|<RESET>
302+
* <BLUE>|<RESET> <CYAN>|<RESET> 6_C
303+
<CYAN>|<RESET> <BLUE>|<RESET><CYAN>/<RESET>
304+
<CYAN>|<RESET><CYAN>/<RESET><BLUE>|<RESET>
305+
* <BLUE>|<RESET> 6_B
306+
<BLUE>|<RESET><BLUE>/<RESET>
307+
* 6_A
308+
EOF
309+
git log --color=always --graph --date-order --pretty=tformat:%s 6_1 6_3 6_5 >actual.colors.raw &&
310+
test_decode_color <actual.colors.raw | sed "s/ *\$//" >actual.colors &&
311+
test_cmp expect.colors actual.colors
312+
'
313+
285314
test_done

0 commit comments

Comments
 (0)