Skip to content

Commit cb0c8f3

Browse files
committed
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.
1 parent 5b109b2 commit cb0c8f3

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

pkg/gui/presentation/graph/graph.go

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -133,25 +133,20 @@ func getNextPipes(prevPipes []*Pipe, commit *models.Commit, getStyle func(c *mod
133133
// a traversed spot is one where a current pipe is starting on, ending on, or passing through
134134
traversedSpots := set.New[int]()
135135

136-
if len(commit.Parents) > 0 { // merge commit
137-
newPipes = append(newPipes, &Pipe{
138-
fromPos: pos,
139-
toPos: pos,
140-
fromHash: commit.Hash,
141-
toHash: commit.Parents[0],
142-
kind: STARTS,
143-
style: getStyle(commit),
144-
})
145-
} else if len(commit.Parents) == 0 { // root commit
146-
newPipes = append(newPipes, &Pipe{
147-
fromPos: pos,
148-
toPos: pos,
149-
fromHash: commit.Hash,
150-
toHash: models.EmptyTreeCommitHash,
151-
kind: STARTS,
152-
style: getStyle(commit),
153-
})
136+
var toHash string
137+
if commit.IsFirstCommit() {
138+
toHash = models.EmptyTreeCommitHash
139+
} else {
140+
toHash = commit.Parents[0]
154141
}
142+
newPipes = append(newPipes, &Pipe{
143+
fromPos: pos,
144+
toPos: pos,
145+
fromHash: commit.Hash,
146+
toHash: toHash,
147+
kind: STARTS,
148+
style: getStyle(commit),
149+
})
155150

156151
traversedSpotsForContinuingPipes := set.New[int]()
157152
for _, pipe := range currentPipes {

0 commit comments

Comments
 (0)