@@ -60,6 +60,12 @@ struct column {
6060 * index into column_colors.
6161 */
6262 unsigned short color ;
63+ /*
64+ * A placeholder column keeps the column of a parentless commit filled
65+ * for one extra row, avoiding a next unrelated commit to be printed
66+ * in the same column.
67+ */
68+ unsigned is_placeholder :1 ;
6369};
6470
6571enum graph_state {
@@ -572,6 +578,7 @@ static void graph_insert_into_new_columns(struct git_graph *graph,
572578 i = graph -> num_new_columns ++ ;
573579 graph -> new_columns [i ].commit = commit ;
574580 graph -> new_columns [i ].color = graph_find_commit_color (graph , commit );
581+ graph -> new_columns [i ].is_placeholder = 0 ;
575582 }
576583
577584 if (graph -> num_parents > 1 && idx > -1 && graph -> merge_layout == -1 ) {
@@ -616,7 +623,7 @@ static void graph_update_columns(struct git_graph *graph)
616623{
617624 struct commit_list * parent ;
618625 int max_new_columns ;
619- int i , seen_this , is_commit_in_columns ;
626+ int i , seen_this , is_commit_in_columns , seems_root ;
620627
621628 /*
622629 * Swap graph->columns with graph->new_columns
@@ -663,6 +670,12 @@ static void graph_update_columns(struct git_graph *graph)
663670 */
664671 seen_this = 0 ;
665672 is_commit_in_columns = 1 ;
673+ /*
674+ * num_parents == 0 means that there are no parents flagged as
675+ * interesting to being shown.
676+ */
677+ seems_root = graph -> num_parents == 0 &&
678+ !(graph -> commit -> object .flags & BOUNDARY );
666679 for (i = 0 ; i <= graph -> num_columns ; i ++ ) {
667680 struct commit * col_commit ;
668681 if (i == graph -> num_columns ) {
@@ -697,11 +710,40 @@ static void graph_update_columns(struct git_graph *graph)
697710 * least 2, even if it has no interesting parents.
698711 * The current commit always takes up at least 2
699712 * spaces.
713+ *
714+ * Check for the commit to seem like a root, no parents
715+ * rendered and that it is not a boundary commit. If so,
716+ * add a placeholder to keep that column filled for
717+ * at least one row.
718+ *
719+ * Prevents the next commit from being inserted
720+ * just below and making the graph confusing.
700721 */
701- if (graph -> num_parents == 0 )
722+ if (seems_root ) {
723+ graph_insert_into_new_columns (graph , graph -> commit , i );
724+ graph -> new_columns [graph -> num_new_columns - 1 ]
725+ .is_placeholder = 1 ;
726+ } else if (graph -> num_parents == 0 ) {
702727 graph -> width += 2 ;
728+ }
703729 } else {
704- graph_insert_into_new_columns (graph , col_commit , -1 );
730+ if (graph -> columns [i ].is_placeholder ) {
731+ /*
732+ * Keep the placeholders if the next commit is
733+ * parentless also, making the indentation cascade.
734+ */
735+ if (!seen_this && seems_root ) {
736+ graph_insert_into_new_columns (graph ,
737+ graph -> columns [i ].commit , i );
738+ graph -> new_columns [graph -> num_new_columns - 1 ]
739+ .is_placeholder = 1 ;
740+ } else if (!seen_this ) {
741+ graph -> mapping [graph -> width ] = -1 ;
742+ graph -> width += 2 ;
743+ }
744+ } else {
745+ graph_insert_into_new_columns (graph , col_commit , -1 );
746+ }
705747 }
706748 }
707749
@@ -872,7 +914,10 @@ static void graph_output_padding_line(struct git_graph *graph,
872914 graph_line_addstr (line , "~ " );
873915 break ;
874916 }
875- graph_line_write_column (line , & graph -> new_columns [i ], '|' );
917+ if (graph -> new_columns [i ].is_placeholder )
918+ graph_line_write_column (line , & graph -> new_columns [i ], ' ' );
919+ else
920+ graph_line_write_column (line , & graph -> new_columns [i ], '|' );
876921 graph_line_addch (line , ' ' );
877922 }
878923}
@@ -1106,7 +1151,13 @@ static void graph_output_commit_line(struct git_graph *graph, struct graph_line
11061151 graph -> mapping [2 * i ] < i ) {
11071152 graph_line_write_column (line , col , '/' );
11081153 } else {
1109- graph_line_write_column (line , col , '|' );
1154+ if (col -> is_placeholder ) {
1155+ if (seen_this )
1156+ continue ;
1157+ graph_line_write_column (line , col , ' ' );
1158+ } else {
1159+ graph_line_write_column (line , col , '|' );
1160+ }
11101161 }
11111162 graph_line_addch (line , ' ' );
11121163 }
@@ -1250,7 +1301,14 @@ static void graph_output_post_merge_line(struct git_graph *graph, struct graph_l
12501301 if (!graph_needs_truncation (graph , i + 1 ))
12511302 graph_line_addch (line , ' ' );
12521303 } else {
1253- graph_line_write_column (line , col , '|' );
1304+ if (col -> is_placeholder ) {
1305+ if (seen_this )
1306+ continue ;
1307+ graph_line_write_column (line , col , ' ' );
1308+ } else {
1309+ graph_line_write_column (line , col , '|' );
1310+ }
1311+
12541312 if (graph -> merge_layout != 0 || i != graph -> commit_index - 1 ) {
12551313 if (parent_col )
12561314 graph_line_write_column (
0 commit comments