diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2015-12-12 22:07:47 +0100 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2015-12-12 22:07:47 +0100 |
commit | f821e1340752dce95f73375dc9a13dcd58d58f82 (patch) | |
tree | d68b7e33aba06f67d3c3e301b4a68f09de0ded6a /commit.go | |
parent | c22c181f70e0afb294513315e9975b9f3f4c1d39 (diff) | |
parent | b543e4e02793a58db25148214ef149cb571792f5 (diff) | |
download | go-git-f821e1340752dce95f73375dc9a13dcd58d58f82.tar.gz |
Merge pull request #9 from mcuadros/blame-cleanupv2.0.0
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) +} |