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