graph: extract logic for moving to GRAPH_PRE_COMMIT state
This computation is repeated in a couple of places and I need to add another condition to it to implement a further improvement to the graph rendering, so I'm extracting this into a function. Signed-off-by: James Coglan <jcoglan@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
James Coglan committed
Oct 15, 2019 at 23:47 UTC
ee7abb5ffaaba8c3fc5f89765609f30d638f63f7
1 file changed
+8
-4
graph.c
+8
-4
@@ -588,6 +588,12 @@ static void graph_update_columns(struct git_graph *graph)
588
graph->mapping_size--;
589
}
590
591
+static int graph_needs_pre_commit_line(struct git_graph *graph)
592
+{
593
+ return graph->num_parents >= 3 &&
594
+ graph->commit_index < (graph->num_columns - 1);
595
+}
596
+
597
void graph_update(struct git_graph *graph, struct commit *commit)
598
{
599
struct commit_list *parent;
@@ -643,8 +649,7 @@ void graph_update(struct git_graph *graph, struct commit *commit)
649
*/
650
if (graph->state != GRAPH_PADDING)
651
graph->state = GRAPH_SKIP;
646
- else if (graph->num_parents >= 3 &&
647
- graph->commit_index < (graph->num_columns - 1))
652
+ else if (graph_needs_pre_commit_line(graph))
653
graph->state = GRAPH_PRE_COMMIT;
654
else
655
graph->state = GRAPH_COMMIT;
@@ -714,8 +719,7 @@ static void graph_output_skip_line(struct git_graph *graph, struct graph_line *l
719
*/
720
graph_line_addstr(line, "...");
721
717
- if (graph->num_parents >= 3 &&
718
- graph->commit_index < (graph->num_columns - 1))
722
+ if (graph_needs_pre_commit_line(graph))
723
graph_update_state(graph, GRAPH_PRE_COMMIT);
724
else
725
graph_update_state(graph, GRAPH_COMMIT);