Skip to content

Commit 91e50b2

Browse files
Adam Simpkinsgitster
authored andcommitted
graph API: use a new color when starting a brand new column
Use a new color for commits that don't have any previously printed children. The following command demonstrates the changes: git log --graph --pretty=tformat:'%h %s%n' -7 481c7a6 18b0793 Now the two independent lines of development are displayed with different colors, instead of both using the same color. Signed-off-by: Adam Simpkins <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f3a87d9 commit 91e50b2

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

graph.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,12 @@ struct git_graph *graph_init(struct rev_info *opt)
225225
graph->num_columns = 0;
226226
graph->num_new_columns = 0;
227227
graph->mapping_size = 0;
228-
graph->default_column_color = 0;
228+
/*
229+
* Start the column color at the maximum value, since we'll
230+
* always increment it for the first commit we output.
231+
* This way we start at 0 for the first commit.
232+
*/
233+
graph->default_column_color = COLUMN_COLORS_MAX - 1;
229234

230235
/*
231236
* Allocate a reasonably large default number of columns
@@ -499,11 +504,14 @@ static void graph_update_columns(struct git_graph *graph)
499504
parent;
500505
parent = next_interesting_parent(graph, parent)) {
501506
/*
502-
* If this is a merge increment the current
507+
* If this is a merge, or the start of a new
508+
* childless column, increment the current
503509
* color.
504510
*/
505-
if (graph->num_parents > 1)
511+
if (graph->num_parents > 1 ||
512+
!is_commit_in_columns) {
506513
graph_increment_column_color(graph);
514+
}
507515
graph_insert_into_new_columns(graph,
508516
parent->item,
509517
&mapping_idx);

0 commit comments

Comments
 (0)