@@ -47,20 +47,6 @@ static void graph_show_strbuf(struct git_graph *graph, struct strbuf const *sb);
4747 * - Limit the number of columns, similar to the way gitk does.
4848 * If we reach more than a specified number of columns, omit
4949 * sections of some columns.
50- *
51- * - The output during the GRAPH_PRE_COMMIT and GRAPH_COLLAPSING states
52- * could be made more compact by printing horizontal lines, instead of
53- * long diagonal lines. For example, during collapsing, something like
54- * this: instead of this:
55- * | | | | | | | | | |
56- * | |_|_|/ | | | |/
57- * |/| | | | | |/|
58- * | | | | | |/| |
59- * |/| | |
60- * | | | |
61- *
62- * If there are several parallel diagonal lines, they will need to be
63- * replaced with horizontal lines on subsequent rows.
6450 */
6551
6652struct column {
@@ -982,6 +968,9 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct strbuf
982968{
983969 int i ;
984970 int * tmp_mapping ;
971+ short used_horizontal = 0 ;
972+ int horizontal_edge = -1 ;
973+ int horizontal_edge_target = -1 ;
985974
986975 /*
987976 * Clear out the new_mapping array
@@ -1019,6 +1008,23 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct strbuf
10191008 * Move to the left by one
10201009 */
10211010 graph -> new_mapping [i - 1 ] = target ;
1011+ /*
1012+ * If there isn't already an edge moving horizontally
1013+ * select this one.
1014+ */
1015+ if (horizontal_edge == -1 ) {
1016+ int j ;
1017+ horizontal_edge = i ;
1018+ horizontal_edge_target = target ;
1019+ /*
1020+ * The variable target is the index of the graph
1021+ * column, and therefore target*2+3 is the
1022+ * actual screen column of the first horizontal
1023+ * line.
1024+ */
1025+ for (j = (target * 2 )+ 3 ; j < (i - 2 ); j += 2 )
1026+ graph -> new_mapping [j ] = target ;
1027+ }
10221028 } else if (graph -> new_mapping [i - 1 ] == target ) {
10231029 /*
10241030 * There is a branch line to our left
@@ -1039,10 +1045,21 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct strbuf
10391045 *
10401046 * The space just to the left of this
10411047 * branch should always be empty.
1048+ *
1049+ * The branch to the left of that space
1050+ * should be our eventual target.
10421051 */
10431052 assert (graph -> new_mapping [i - 1 ] > target );
10441053 assert (graph -> new_mapping [i - 2 ] < 0 );
1054+ assert (graph -> new_mapping [i - 3 ] == target );
10451055 graph -> new_mapping [i - 2 ] = target ;
1056+ /*
1057+ * Mark this branch as the horizontal edge to
1058+ * prevent any other edges from moving
1059+ * horizontally.
1060+ */
1061+ if (horizontal_edge == -1 )
1062+ horizontal_edge = i ;
10461063 }
10471064 }
10481065
@@ -1061,8 +1078,23 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct strbuf
10611078 strbuf_addch (sb , ' ' );
10621079 else if (target * 2 == i )
10631080 strbuf_write_column (sb , & graph -> new_columns [target ], '|' );
1064- else
1081+ else if (target == horizontal_edge_target &&
1082+ i != horizontal_edge - 1 ) {
1083+ /*
1084+ * Set the mappings for all but the
1085+ * first segment to -1 so that they
1086+ * won't continue into the next line.
1087+ */
1088+ if (i != (target * 2 )+ 3 )
1089+ graph -> new_mapping [i ] = -1 ;
1090+ used_horizontal = 1 ;
1091+ strbuf_write_column (sb , & graph -> new_columns [target ], '_' );
1092+ } else {
1093+ if (used_horizontal && i < horizontal_edge )
1094+ graph -> new_mapping [i ] = -1 ;
10651095 strbuf_write_column (sb , & graph -> new_columns [target ], '/' );
1096+
1097+ }
10661098 }
10671099
10681100 graph_pad_horizontally (graph , sb , graph -> mapping_size );
0 commit comments