1package git
 2
 3import (
 4	"github.com/gogs/git-module"
 5)
 6
 7var (
 8	ZeroHash Hash = git.EmptyID
 9)
10
11// Hash represents a git hash.
12type Hash string
13
14// String returns the string representation of a hash as a string.
15func (h Hash) String() string {
16	return string(h)
17}
18
19// SHA1 represents the hash as a SHA1.
20func (h Hash) SHA1() *git.SHA1 {
21	return git.MustIDFromString(h.String())
22}
23
24// Commit is a wrapper around git.Commit with helper methods.
25type Commit struct {
26	*git.Commit
27	Hash Hash
28}
29
30// Commits is a list of commits.
31type Commits []*Commit
32
33// Len implements sort.Interface.
34func (cl Commits) Len() int { return len(cl) }
35
36// Swap implements sort.Interface.
37func (cl Commits) Swap(i, j int) { cl[i], cl[j] = cl[j], cl[i] }
38
39// Less implements sort.Interface.
40func (cl Commits) Less(i, j int) bool {
41	return cl[i].Author.When.After(cl[j].Author.When)
42}