aboutsummaryrefslogtreecommitdiffstats
path: root/references.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-04-11 23:16:48 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2017-04-11 23:16:48 +0200
commit7a428a915ce2b7bb0f4fc6dcee77932ebacfabbf (patch)
treea116c49d89ae0450c9999a85896d1a10ba7d8a0b /references.go
parent116fed7ea746255805f5664d9b6fd7cdb1b52663 (diff)
parent9b45f468c61a0756dd19d09b64c2b1a88cc99ec5 (diff)
downloadgo-git-7a428a915ce2b7bb0f4fc6dcee77932ebacfabbf.tar.gz
merge, Repository.Log
Diffstat (limited to 'references.go')
-rw-r--r--references.go28
1 files changed, 26 insertions, 2 deletions
diff --git a/references.go b/references.go
index 957d741..fc81103 100644
--- a/references.go
+++ b/references.go
@@ -2,6 +2,7 @@ package git
import (
"io"
+ "sort"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/object"
@@ -23,19 +24,42 @@ import (
// - Cherry-picks are not detected unless there are no commits between them and
// therefore can appear repeated in the list. (see git path-id for hints on how
// to fix this).
-func References(c *object.Commit, path string) ([]*object.Commit, error) {
+func references(c *object.Commit, path string) ([]*object.Commit, error) {
var result []*object.Commit
seen := make(map[plumbing.Hash]struct{}, 0)
if err := walkGraph(&result, &seen, c, path); err != nil {
return nil, err
}
- object.SortCommits(result)
+ // TODO result should be returned without ordering
+ sortCommits(result)
// for merges of identical cherry-picks
return removeComp(path, result, equivalent)
}
+type commitSorterer struct {
+ l []*object.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 sorts a commit list by commit date, from older to newer.
+func sortCommits(l []*object.Commit) {
+ s := &commitSorterer{l}
+ sort.Sort(s)
+}
+
// Recursive traversal of the commit graph, generating a linear history of the
// path.
func walkGraph(result *[]*object.Commit, seen *map[plumbing.Hash]struct{}, current *object.Commit, path string) error {