@@ -47,20 +47,6 @@ static void graph_show_strbuf(struct git_graph *graph, struct strbuf const *sb);
47
47
* - Limit the number of columns, similar to the way gitk does.
48
48
* If we reach more than a specified number of columns, omit
49
49
* 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.
64
50
*/
65
51
66
52
struct column {
@@ -982,6 +968,9 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct strbuf
982
968
{
983
969
int i ;
984
970
int * tmp_mapping ;
971
+ short used_horizontal = 0 ;
972
+ int horizontal_edge = -1 ;
973
+ int horizontal_edge_target = -1 ;
985
974
986
975
/*
987
976
* Clear out the new_mapping array
@@ -1019,6 +1008,23 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct strbuf
1019
1008
* Move to the left by one
1020
1009
*/
1021
1010
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
+ }
1022
1028
} else if (graph -> new_mapping [i - 1 ] == target ) {
1023
1029
/*
1024
1030
* There is a branch line to our left
@@ -1039,10 +1045,21 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct strbuf
1039
1045
*
1040
1046
* The space just to the left of this
1041
1047
* branch should always be empty.
1048
+ *
1049
+ * The branch to the left of that space
1050
+ * should be our eventual target.
1042
1051
*/
1043
1052
assert (graph -> new_mapping [i - 1 ] > target );
1044
1053
assert (graph -> new_mapping [i - 2 ] < 0 );
1054
+ assert (graph -> new_mapping [i - 3 ] == target );
1045
1055
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 ;
1046
1063
}
1047
1064
}
1048
1065
@@ -1061,8 +1078,23 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct strbuf
1061
1078
strbuf_addch (sb , ' ' );
1062
1079
else if (target * 2 == i )
1063
1080
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 ;
1065
1095
strbuf_write_column (sb , & graph -> new_columns [target ], '/' );
1096
+
1097
+ }
1066
1098
}
1067
1099
1068
1100
graph_pad_horizontally (graph , sb , graph -> mapping_size );
0 commit comments