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

graph API: Use horizontal lines for more compact graphs

Use horizontal lines instead of long diagonal lines during the collapsing state of graph rendering. For example what used to be: | | | | | | | | |/ | | |/| | |/| | |/| | | | | | | is now | | | | | | |_|_|/ |/| | | | | | | This results in more compact and legible graphs. Signed-off-by: Allan Caffee <allan.caffee@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Allan Caffee committed Apr 21, 2009 at 08:47 UTC eaf158f8bd7615562e1fa84711ea465f387a3c9d
2 files changed +49 -19
graph.c
+47 -15
@@ -47,20 +47,6 @@ static void graph_show_strbuf(struct git_graph *graph, struct strbuf const *sb);
47 * - Limit the number of columns, similar to the way gitk does.
48 * If we reach more than a specified number of columns, omit
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.
50 */
51
52 struct column {
@@ -982,6 +968,9 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct strbuf
968 {
969 int i;
970 int *tmp_mapping;
971 + short used_horizontal = 0;
972 + int horizontal_edge = -1;
973 + int horizontal_edge_target = -1;
974
975 /*
976 * Clear out the new_mapping array
@@ -1019,6 +1008,23 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct strbuf
1008 * Move to the left by one
1009 */
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 + }
1028 } else if (graph->new_mapping[i - 1] == target) {
1029 /*
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
1045 *
1046 * The space just to the left of this
1047 * branch should always be empty.
1048 + *
1049 + * The branch to the left of that space
1050 + * should be our eventual target.
1051 */
1052 assert(graph->new_mapping[i - 1] > target);
1053 assert(graph->new_mapping[i - 2] < 0);
1054 + assert(graph->new_mapping[i - 3] == target);
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;
1063 }
1064 }
1065
@@ -1061,8 +1078,23 @@ static void graph_output_collapsing_line(struct git_graph *graph, struct strbuf
1078 strbuf_addch(sb, ' ');
1079 else if (target * 2 == i)
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;
1095 strbuf_write_column(sb, &graph->new_columns[target], '/');
1096 +
1097 + }
1098 }
1099
1100 graph_pad_horizontally(graph, sb, graph->mapping_size);
t/t4202-log.sh
+2 -4
@@ -298,14 +298,12 @@ cat > expect <<\EOF
298 * | | | Merge branch 'side'
299 |\ \ \ \
300 | * | | | side-2
301 -| | | |/
302 -| | |/|
301 +| | |_|/
302 | |/| |
303 | * | | side-1
304 * | | | Second
305 * | | | sixth
307 -| | |/
308 -| |/|
306 +| |_|/
307 |/| |
308 * | | fifth
309 * | | fourth