#!/bin/sh

. libtest.sh
. libgit.sh

steps '
	:save-display diff.screen
'

git_init

test_tig show <<EOF
commit 1b4c64b595aeb4de1d317d669faacd3c1d82f0b0
Author: Sven Wegener <sven.wegener@example.net>
Date:   Sun Jul 2 15:01:24 2017 +0200

    graph: Optimize initial and merge calculation
    
    The initial and merge flags do not depend on any column-specific
    information, so calculate them only once.
    
    Signed-off-by: Sven Wegener <sven.wegener@example.net>
---
 src/graph-v2.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/graph-v2.c b/src/graph-v2.c
index 4cf3d9e..ced6838 100644
--- a/src/graph-v2.c
+++ b/src/graph-v2.c
@@ -683,6 +683,9 @@ graph_generate_symbols(struct graph_v2 *graph, struct graph_canvas *canvas)
 	struct graph_row *row = &graph->row;
 	struct graph_row *next_row = &graph->next_row;
 	struct graph_row *parents = &graph->parents;
+	int commits = commits_in_row(parents);
+	int initial = commits < 1;
+	int merge = commits > 1;
 	int pos;
 
 	for (pos = 0; pos < row->size; pos++) {
@@ -692,8 +695,8 @@ graph_generate_symbols(struct graph_v2 *graph, struct graph_canvas *canvas)
 
 		symbol->commit            = (pos == graph->position);
 		symbol->boundary          = (pos == graph->position && next_row->columns[pos].symbol.boundary);
-		symbol->initial           = (commits_in_row(parents) < 1);
-		symbol->merge             = (commits_in_row(parents) > 1);
+		symbol->initial           = initial;
+		symbol->merge             = merge;
 
 		symbol->continued_down    = continued_down(row, next_row, pos);
 		symbol->continued_up      = continued_down(prev_row, row, pos);
EOF

assert_equals 'diff.screen' <<EOF
commit 1b4c64b595aeb4de1d317d669faacd3c1d82f0b0
Author: Sven Wegener <sven.wegener@example.net>
Date:   Sun Jul 2 15:01:24 2017 +0200
 
    graph: Optimize initial and merge calculation
 
    The initial and merge flags do not depend on any column-specific
    information, so calculate them only once.
 
    Signed-off-by: Sven Wegener <sven.wegener@example.net>
---
 src/graph-v2.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
 
diff --git a/src/graph-v2.c b/src/graph-v2.c
index 4cf3d9e..ced6838 100644
--- a/src/graph-v2.c
+++ b/src/graph-v2.c
@@ -683,6 +683,9 @@ graph_generate_symbols(struct graph_v2 *graph, struct graph_
        struct graph_row *row = &graph->row;
        struct graph_row *next_row = &graph->next_row;
        struct graph_row *parents = &graph->parents;
+       int commits = commits_in_row(parents);
+       int initial = commits < 1;
+       int merge = commits > 1;
        int pos;
 
        for (pos = 0; pos < row->size; pos++) {
[diff] 1b4c64b595aeb4de1d317d669faacd3c1d82f0b0 - line 1 of 39               71%
EOF
