commit.go

 1package git
 2
 3import (
 4	"regexp"
 5
 6	git "github.com/aymanbagabas/git-module"
 7)
 8
 9// ZeroID is the zero hash.
10const ZeroID = git.EmptyID
11
12// IsZeroHash returns whether the hash is a zero hash.
13func IsZeroHash(h string) bool {
14	pattern := regexp.MustCompile(`^0{40,}$`)
15	return pattern.MatchString(h)
16}
17
18// Commit is a wrapper around git.Commit with helper methods.
19type Commit = git.Commit
20
21// Commits is a list of commits.
22type Commits []*Commit
23
24// Len implements sort.Interface.
25func (cl Commits) Len() int { return len(cl) }
26
27// Swap implements sort.Interface.
28func (cl Commits) Swap(i, j int) { cl[i], cl[j] = cl[j], cl[i] }
29
30// Less implements sort.Interface.
31func (cl Commits) Less(i, j int) bool {
32	return cl[i].Author.When.After(cl[j].Author.When)
33}