diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2015-12-12 03:22:52 +0100 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2015-12-12 03:22:52 +0100 |
commit | b543e4e02793a58db25148214ef149cb571792f5 (patch) | |
tree | d68b7e33aba06f67d3c3e301b4a68f09de0ded6a /commit.go | |
parent | c22c181f70e0afb294513315e9975b9f3f4c1d39 (diff) | |
download | go-git-b543e4e02793a58db25148214ef149cb571792f5.tar.gz |
blame code reorganization, and mutting the test
Diffstat (limited to 'commit.go')
-rw-r--r-- | commit.go | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -6,6 +6,7 @@ import ( "errors" "fmt" "io" + "sort" "gopkg.in/src-d/go-git.v2/core" ) @@ -159,3 +160,25 @@ func (i *iter) Close() { defer func() { i.IsClosed = true }() close(i.ch) } + +type commitSorterer struct { + l []*Commit +} + +func (s commitSorterer) Len() int { + return len(s.l) +} + +func (s commitSorterer) Less(i, j int) bool { + return s.l[i].Committer.When.Before(s.l[j].Committer.When) +} + +func (s commitSorterer) Swap(i, j int) { + s.l[i], s.l[j] = s.l[j], s.l[i] +} + +// SortCommits sort a commit list by commit date, from older to newer. +func SortCommits(l []*Commit) { + s := &commitSorterer{l} + sort.Sort(s) +} |