Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions pkg/commands/models/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (
"github.com/stefanhaller/git-todo-parser/todo"
)

// Special commit hash for empty tree object
// Empty tree object hashes for SHA-1 and SHA-256 repos.
const EmptyTreeCommitHash = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
const EmptyTreeCommitHashSHA256 = "6ef19b41225c5369f1c104d45d8d85efa9b057b53b14b4b9b939dd74decc5321"

type CommitStatus uint8

Expand Down Expand Up @@ -122,11 +123,20 @@ func (c *Commit) ShortRefName() string {

func (c *Commit) ParentRefName() string {
if c.IsFirstCommit() {
return EmptyTreeCommitHash
return c.emptyTreeHash()
}
return c.RefName() + "^"
}

// emptyTreeHash returns the empty tree object hash matching this repo's
// object format. SHA-256 repos produce 64-char hashes; SHA-1 repos 40-char.
func (c *Commit) emptyTreeHash() string {
if len(c.Hash()) > 40 {
return EmptyTreeCommitHashSHA256
}
return EmptyTreeCommitHash
}

func (c *Commit) Parents() []string {
return lo.Map(c.parents, func(s *string, _ int) string { return *s })
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/gui/presentation/graph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,11 @@ func getNextPipes(prevPipes []Pipe, commit *models.Commit, getStyle func(c *mode

var toHash *string
if commit.IsFirstCommit() {
toHash = &EmptyTreeCommitHash
emptyHash := EmptyTreeCommitHash
if len(commit.Hash()) > 40 {
emptyHash = models.EmptyTreeCommitHashSHA256
}
toHash = &emptyHash
} else {
toHash = commit.ParentPtrs()[0]
}
Expand Down
Loading