diff --git a/doc/tigrc.5.adoc b/doc/tigrc.5.adoc index 5a11e181b..9f3f33aee 100644 --- a/doc/tigrc.5.adoc +++ b/doc/tigrc.5.adoc @@ -460,8 +460,13 @@ author:: sizing content, up to this limit. commit-title:: - - 'graph' (mixed) [no|v2|v1]: Whether to show the revision graph in the - main view on start-up. "v1" refers to the old graph rendering, which + - 'graph' (mixed) [no|v2|v2-horizontal-crossover|v1]: + Whether to show the revision graph in the main view on start-up. + "v2" refers to the newer graph rendering where a vertical path is placed over a horizontal path, + but the horizontal path is miscolored. + "v2-horizontal-crossover" refers to the newer graph rendering where a horizontal path is placed over a vertical path, + and the horizontal path is correctly colored. + "v1" refers to the old graph rendering, which is less accurate but faster and thus recommended in large repositories. See also the 'line-graphics' options. - 'refs' (bool): Whether to show references (branches, tags, and diff --git a/include/tig/types.h b/include/tig/types.h index 6bc481af7..346205a19 100644 --- a/include/tig/types.h +++ b/include/tig/types.h @@ -82,6 +82,7 @@ bool map_enum_do(const struct enum_map_entry *map, size_t map_size, int *value, #define GRAPH_DISPLAY_ENUM(_) \ _(GRAPH_DISPLAY, NO), \ _(GRAPH_DISPLAY, V2), \ + _(GRAPH_DISPLAY, V2_HORIZONTAL_CROSSOVER), \ _(GRAPH_DISPLAY, V1) #define DATE_ENUM(_) \ diff --git a/src/graph-v2.c b/src/graph-v2.c index 46504a85e..f479fb98f 100644 --- a/src/graph-v2.c +++ b/src/graph-v2.c @@ -695,7 +695,6 @@ graph_generate_symbols(struct graph_v2 *graph, struct graph_canvas *canvas) for (pos = 0; pos < row->size; pos++) { struct graph_column *column = &row->columns[pos]; struct graph_symbol *symbol = &column->symbol; - const char *id = next_row->columns[pos].id; symbol->commit = (pos == graph->position); symbol->boundary = (pos == graph->position && next_row->columns[pos].symbol.boundary); @@ -723,10 +722,8 @@ graph_generate_symbols(struct graph_v2 *graph, struct graph_canvas *canvas) symbol->new_column = new_column(row, prev_row, pos); symbol->empty = (!graph_column_has_commit(&row->columns[pos])); - if (graph_column_has_commit(column)) { - id = column->id; - } - symbol->color = get_color(graph, id); + // Do initial assignment of symbol colors + symbol->color = get_color(graph, column->id ? column->id : next_row->columns[pos].id); graph_canvas_append_symbol(graph, canvas, symbol); } @@ -1085,6 +1082,15 @@ graph_symbol_to_utf8(const struct graph_symbol *symbol) return " "; } +static const char * +graph_symbol_to_utf8_horiz(const struct graph_symbol *symbol) +{ + return + graph_symbol_cross_over(symbol) ? "──" + : graph_symbol_turn_down_cross_over(symbol) ? " ╭" + : graph_symbol_to_utf8(symbol); +} + static const chtype * graph_symbol_to_chtype(const struct graph_symbol *symbol) { @@ -1156,6 +1162,16 @@ graph_symbol_to_chtype(const struct graph_symbol *symbol) return graphics; } +static const chtype * +graph_symbol_to_chtype_horiz(const struct graph_symbol *symbol) +{ + static chtype graphics[2]; + return + graph_symbol_cross_over(symbol) ? (graphics[0] = ACS_HLINE, graphics[1] = ACS_HLINE, graphics) + : graph_symbol_turn_down_cross_over(symbol) ? (graphics[0] = ' ', graphics[1] = ACS_ULCORNER, graphics) + : graph_symbol_to_chtype(symbol); +} + static const char * graph_symbol_to_ascii(const struct graph_symbol *symbol) { @@ -1208,6 +1224,33 @@ graph_symbol_to_ascii(const struct graph_symbol *symbol) return " "; } +static const char * +graph_symbol_to_ascii_horiz(const struct graph_symbol *symbol) +{ + return + graph_symbol_cross_over(symbol) ? "--" + : graph_symbol_turn_down_cross_over(symbol) ? " ." + : graph_symbol_to_ascii(symbol); +} + +/* Re-color the symbols array of the given graph_canvas + * so that horizontal cross-over symbols are properly colored + */ +static void +graph_symbol_recolor(const struct graph_canvas *canvas) +{ + struct graph_symbol *sy = &canvas->symbols[canvas->size - 1]; + size_t merge_c = 0; + int i; + + for (i = canvas->size - 1; i >= 0; i--, sy--) { + if (graph_symbol_merge(sy) || graph_symbol_turn_left(sy)) + if (!merge_c) merge_c = sy->color; + if (graph_symbol_cross_over(sy)) + sy->color = merge_c; + } +} + static void graph_foreach_symbol(const struct graph *graph, const struct graph_canvas *canvas, graph_symbol_iterator_fn fn, void *data) @@ -1223,8 +1266,16 @@ graph_foreach_symbol(const struct graph *graph, const struct graph_canvas *canva } } +static void +graph_foreach_symbol_horiz(const struct graph *graph, const struct graph_canvas *canvas, + graph_symbol_iterator_fn fn, void *data) +{ + graph_symbol_recolor(canvas); + graph_foreach_symbol(graph, canvas, fn, data); +} + struct graph * -init_graph_v2(void) +init_graph_v2(bool crossover) { struct graph_v2 *graph = calloc(1, sizeof(*graph)); struct graph *api; @@ -1240,10 +1291,10 @@ init_graph_v2(void) api->add_parent = graph_add_parent; api->is_merge = graph_is_merge; api->render_parents = graph_render_parents; - api->foreach_symbol = graph_foreach_symbol; - api->symbol_to_ascii = graph_symbol_to_ascii; - api->symbol_to_utf8 = graph_symbol_to_utf8; - api->symbol_to_chtype = graph_symbol_to_chtype; + api->foreach_symbol = crossover ? graph_foreach_symbol_horiz : graph_foreach_symbol ; + api->symbol_to_ascii = crossover ? graph_symbol_to_ascii_horiz : graph_symbol_to_ascii ; + api->symbol_to_utf8 = crossover ? graph_symbol_to_utf8_horiz : graph_symbol_to_utf8 ; + api->symbol_to_chtype = crossover ? graph_symbol_to_chtype_horiz : graph_symbol_to_chtype ; return api; } diff --git a/src/graph.c b/src/graph.c index 6a4e041d6..b7acea1a7 100644 --- a/src/graph.c +++ b/src/graph.c @@ -15,7 +15,7 @@ #include "tig/graph.h" struct graph *init_graph_v1(void); -struct graph *init_graph_v2(void); +struct graph *init_graph_v2(bool); struct graph * init_graph(enum graph_display display) @@ -23,7 +23,9 @@ init_graph(enum graph_display display) if (display == GRAPH_DISPLAY_V1) return init_graph_v1(); if (display == GRAPH_DISPLAY_V2) - return init_graph_v2(); + return init_graph_v2(false); + if (display == GRAPH_DISPLAY_V2_HORIZONTAL_CROSSOVER) + return init_graph_v2(true); return NULL; } diff --git a/test/main/default-test b/test/main/default-test index 0ed7317d2..cf5d80c53 100755 --- a/test/main/default-test +++ b/test/main/default-test @@ -22,6 +22,7 @@ steps ' :save-display main-no-refs.screen :toggle commit-title-graph :toggle commit-title-graph + :toggle commit-title-graph :save-display main-no-graph.screen :957f2b368e6fa5c0757f36b1441e32729ee5e9c7