From cb0c8f39bf4e9973fd96d2e76162bae92f847224 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 26 Apr 2025 20:51:53 +0200 Subject: [PATCH] Simplify code and fix comment The "// merge commit" comment was plain wrong, this is any commit that has a parent, merge or not. The "else if" condition was unnecessary, a plain "else" would have been enough. But the code in the two blocks was almost identical, so extract the one thing that was different and unify it. And while we're at it, use IsFirstCommit() instead of counting parents. --- pkg/gui/presentation/graph/graph.go | 31 ++++++++++++----------------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/pkg/gui/presentation/graph/graph.go b/pkg/gui/presentation/graph/graph.go index ae4401a13..31bbe529e 100644 --- a/pkg/gui/presentation/graph/graph.go +++ b/pkg/gui/presentation/graph/graph.go @@ -133,25 +133,20 @@ func getNextPipes(prevPipes []*Pipe, commit *models.Commit, getStyle func(c *mod // a traversed spot is one where a current pipe is starting on, ending on, or passing through traversedSpots := set.New[int]() - if len(commit.Parents) > 0 { // merge commit - newPipes = append(newPipes, &Pipe{ - fromPos: pos, - toPos: pos, - fromHash: commit.Hash, - toHash: commit.Parents[0], - kind: STARTS, - style: getStyle(commit), - }) - } else if len(commit.Parents) == 0 { // root commit - newPipes = append(newPipes, &Pipe{ - fromPos: pos, - toPos: pos, - fromHash: commit.Hash, - toHash: models.EmptyTreeCommitHash, - kind: STARTS, - style: getStyle(commit), - }) + var toHash string + if commit.IsFirstCommit() { + toHash = models.EmptyTreeCommitHash + } else { + toHash = commit.Parents[0] } + newPipes = append(newPipes, &Pipe{ + fromPos: pos, + toPos: pos, + fromHash: commit.Hash, + toHash: toHash, + kind: STARTS, + style: getStyle(commit), + }) traversedSpotsForContinuingPipes := set.New[int]() for _, pipe := range currentPipes {