@matheusbsbs / matheus-bagliano / commits / a1087c9367
Fork 0

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 <peff@peff.net> Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Jan 7, 2020 at 21:27 UTC a1087c93677bc0304c98f14915b1843e470e4a55
2 files changed +38 -4
graph.c
+9 -4
@@ -1063,7 +1063,7 @@ static void graph_output_post_merge_line(struct git_graph *graph, struct graph_l
1063 int i, j;
1064
1065 struct commit_list *first_parent = first_interesting_parent(graph);
1066 - int seen_parent = 0;
1066 + struct column *parent_col = NULL;
1067
1068 /*
1069 * Output the post-merge row
@@ -1117,12 +1117,17 @@ static void graph_output_post_merge_line(struct git_graph *graph, struct graph_l
1117 graph_line_addch(line, ' ');
1118 } else {
1119 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 + }
1127 }
1128
1129 if (col_commit == first_parent->item)
1125 - seen_parent = 1;
1130 + parent_col = col;
1131 }
1132
1133 /*
t/t4215-log-skewed-merges.sh
+29
@@ -282,4 +282,33 @@ test_expect_success 'log --graph with multiple tips' '
282 EOF
283 '
284
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 +
314 test_done