aboutsummaryrefslogtreecommitdiffstats
path: root/commit.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2015-12-12 03:22:52 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2015-12-12 03:22:52 +0100
commitb543e4e02793a58db25148214ef149cb571792f5 (patch)
treed68b7e33aba06f67d3c3e301b4a68f09de0ded6a /commit.go
parentc22c181f70e0afb294513315e9975b9f3f4c1d39 (diff)
downloadgo-git-b543e4e02793a58db25148214ef149cb571792f5.tar.gz
blame code reorganization, and mutting the test
Diffstat (limited to 'commit.go')
-rw-r--r--commit.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/commit.go b/commit.go
index 99dbf37..1dd09ab 100644
--- a/commit.go
+++ b/commit.go
@@ -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)
+}