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.
This commit is contained in:
Stefan Haller 2025-04-26 20:51:53 +02:00
parent 5b109b2dd6
commit cb0c8f39bf

View file

@ -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 {